highlighter 0.2.0.pre.alpha → 0.3.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: b858676f9797dd49895ba65127dad51d3e4884592a7c542f22b9e120b8c05618
4
- data.tar.gz: '049a27f4096feba8cf4967fea14d249cee3d9093416206e99389813966b01420'
3
+ metadata.gz: 0da81f118da4f0f966398170d013bfbde42783d862a416b668d28f7680036ea1
4
+ data.tar.gz: b4419445f9c3427a7c65b4f12d138f17cc86f74d65587ee24ce45f3b8c0f09ab
5
5
  SHA512:
6
- metadata.gz: 7444b6856724a83cb30a8533164967cf949bd9e279091d593123ef9c694a6f0b581bfe01ccceba6c7252725bd64a7db185372e1a0ab495183ab6c4e216fdb225
7
- data.tar.gz: b04bd46c3ba05d7d8deca7a17b2807ee1c7e620492d5f1f96442cd47aefbf4e8dad78608c1a298f24ed327bff2bead87ad7fabc8391db592dee6e59541784d8e
6
+ metadata.gz: e7f0ef49bebdc089c5d0a11da23aaad9fcddb68dc5f21297b0505451ea0d4ea3e10345bf0884964d653567aa9c37ae61f7263a00f42c291d94270d14a6ffbb43
7
+ data.tar.gz: 0ff8249c987ba58b2a6a585d0caa3e8655c17d0af07ce5599ad29126ccbf890f5f7719f6401946b5c87966ada2cb3757447d0788230e8a67c7fa1447b49f8d78
data/CHANGELOG.md CHANGED
@@ -7,3 +7,7 @@
7
7
  ## [0.2.0-alpha] - 2022-09-02
8
8
 
9
9
  - Feature: add support to assign serializers on the fly
10
+
11
+ ## [0.3.0-alpha] - 2022-09-03
12
+
13
+ - Feature: rename attribute
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- highlighter (0.2.0.pre.alpha)
4
+ highlighter (0.3.0.pre.alpha)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -98,6 +98,21 @@ end
98
98
  ```ruby
99
99
  UserSerializer.new(user, custom_serializer: CarSerializer).to_h
100
100
  ```
101
+ Renaming attribute:
102
+ ```ruby
103
+ class UserSerializer
104
+ include Highlighter::Serializer
105
+
106
+ attribute :id
107
+ attribute :name, rename_to: :full_name
108
+ end
109
+ ```
110
+ ```ruby
111
+ {
112
+ id: 1,
113
+ full_name: "Kelly"
114
+ }
115
+ ```
101
116
  ## Development
102
117
 
103
118
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -3,11 +3,16 @@
3
3
  module Highlighter
4
4
  # Holds info on attribute
5
5
  class Attribute
6
- attr_reader :name, :serializer
6
+ attr_reader :field, :serializer, :rename_to
7
7
 
8
- def initialize(name:, serializer: nil)
9
- @name = name
8
+ def initialize(field:, serializer: nil, rename_to: nil)
9
+ @field = field
10
10
  @serializer = serializer
11
+ @rename_to = rename_to
12
+ end
13
+
14
+ def name
15
+ rename_to.nil? ? field : rename_to
11
16
  end
12
17
  end
13
18
  end
@@ -15,7 +15,7 @@ module Highlighter
15
15
  end
16
16
 
17
17
  def call
18
- value = object.send(attribute.name)
18
+ value = object.send(attribute.field)
19
19
  return serialize_array(value) if value.instance_of? Array
20
20
 
21
21
  apply_serializer(value, attribute)
@@ -23,9 +23,9 @@ module Highlighter
23
23
 
24
24
  # Add methods to expose and set up attributes
25
25
  module ClassMethods
26
- def attribute(name, serializer: nil)
26
+ def attribute(field, serializer: nil, rename_to: nil)
27
27
  instance_variable_set(:@attributes, []) unless instance_variable_defined?(:@attributes)
28
- instance_variable_get(:@attributes) << Attribute.new(name:, serializer:)
28
+ instance_variable_get(:@attributes) << Attribute.new(field:, serializer:, rename_to:)
29
29
  end
30
30
 
31
31
  def attributes
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Highlighter
4
- VERSION = "0.2.0-alpha"
4
+ VERSION = "0.3.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.2.0.pre.alpha
4
+ version: 0.3.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-02 00:00:00.000000000 Z
11
+ date: 2022-09-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Serializer ruby objects in simple and straightforward way
14
14
  email: