highlighter 0.4.0.pre.alpha → 0.5.0.pre.alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc57165cc3381a2749507abc7746f95d2ede9786820b7ff3e8d2f9624981fd66
4
- data.tar.gz: 593a5b19b6d616a407dd7b214186c43d3d478514f2607b318957485e717dcb21
3
+ metadata.gz: fed8b6305a5a4231734f7658d2577617ad4c32df1ec070871371c70225ae5296
4
+ data.tar.gz: f2c18df64f442916800fc6011849cce93e1256e4bf8a3ec93830e87bf3eefd0b
5
5
  SHA512:
6
- metadata.gz: 70557187e4553b5049f2bf15da03c5f40710b6cc5daf133c15190d51d01193272f147d91e14b7c43a632c832abcfef2325cd2ae5b20608a3f95080c2525dc45d
7
- data.tar.gz: 9601811f3dc47ef0396432d4fa949d1098a95dee414e7d3e921f59ee8662ce3a884d1a453e0434698c8763b2127d4b3b77630f3cf6e34ace048d944528eafbd3
6
+ metadata.gz: 79a2cb71a0e784547f3f10e006f22a96f516b8428b3a7e66892bdf067dfa8c9ddd97ce3dc3b338fe88c22a88a3d28ca3050b0ccc4f7fc359cda9f815b682e193
7
+ data.tar.gz: 85244d986e0ff0c5545e74f6df9d740f8f1f97af0d9ad2e890a80ca5b0d9b8cf3384b872abdacc74d4f1f593974da9d7c8f171a5a2986eed2008702b0a4cb7db
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- highlighter (0.4.0.pre.alpha)
4
+ highlighter (0.5.0.pre.alpha)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Highlighter
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/highlighter`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ An easy way to serialize ruby objects :)
6
4
 
7
5
  ## Installation
8
6
 
@@ -3,16 +3,21 @@
3
3
  module Highlighter
4
4
  # Holds info on attribute
5
5
  class Attribute
6
- attr_reader :field, :serializer, :rename_to
6
+ attr_reader :field, :serializer, :rename_to, :block
7
7
 
8
- def initialize(field:, serializer: nil, rename_to: nil)
8
+ def initialize(field:, serializer: nil, rename_to: nil, &block)
9
9
  @field = field
10
10
  @serializer = serializer
11
11
  @rename_to = rename_to
12
+ @block = block
12
13
  end
13
14
 
14
15
  def name
15
16
  rename_to.nil? ? field : rename_to
16
17
  end
18
+
19
+ def block?
20
+ !block.nil?
21
+ end
17
22
  end
18
23
  end
@@ -15,6 +15,8 @@ module Highlighter
15
15
  end
16
16
 
17
17
  def call
18
+ return attribute.block.call(object) if attribute.block?
19
+
18
20
  value = object.send(attribute.field)
19
21
  return serialize_array(value) if value.instance_of? Array
20
22
 
@@ -23,8 +23,12 @@ module Highlighter
23
23
 
24
24
  # Add methods to expose and set up attributes
25
25
  module ClassMethods
26
- def attribute(field, serializer: nil, rename_to: nil)
27
- attribute_list << Attribute.new(field:, serializer:, rename_to:)
26
+ def attribute(field, serializer: nil, rename_to: nil, &block)
27
+ attribute_list << if block_given?
28
+ Attribute.new(field:, serializer:, rename_to:, &block)
29
+ else
30
+ Attribute.new(field:, serializer:, rename_to:)
31
+ end
28
32
  end
29
33
 
30
34
  def attributes(*fields)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Highlighter
4
- VERSION = "0.4.0-alpha"
4
+ VERSION = "0.5.0-alpha"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: highlighter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.pre.alpha
4
+ version: 0.5.0.pre.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caio Rodriguez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-04 00:00:00.000000000 Z
11
+ date: 2022-09-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Serializer ruby objects in simple and straightforward way
14
14
  email: