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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +15 -0
- data/lib/highlighter/attribute.rb +8 -3
- data/lib/highlighter/commands/attribute_serializer.rb +1 -1
- data/lib/highlighter/serializer.rb +2 -2
- data/lib/highlighter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0da81f118da4f0f966398170d013bfbde42783d862a416b668d28f7680036ea1
|
4
|
+
data.tar.gz: b4419445f9c3427a7c65b4f12d138f17cc86f74d65587ee24ce45f3b8c0f09ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7f0ef49bebdc089c5d0a11da23aaad9fcddb68dc5f21297b0505451ea0d4ea3e10345bf0884964d653567aa9c37ae61f7263a00f42c291d94270d14a6ffbb43
|
7
|
+
data.tar.gz: 0ff8249c987ba58b2a6a585d0caa3e8655c17d0af07ce5599ad29126ccbf890f5f7719f6401946b5c87966ada2cb3757447d0788230e8a67c7fa1447b49f8d78
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
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 :
|
6
|
+
attr_reader :field, :serializer, :rename_to
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@
|
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
|
@@ -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(
|
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(
|
28
|
+
instance_variable_get(:@attributes) << Attribute.new(field:, serializer:, rename_to:)
|
29
29
|
end
|
30
30
|
|
31
31
|
def attributes
|
data/lib/highlighter/version.rb
CHANGED
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
|
+
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-
|
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:
|