as_json_representations 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +4 -0
- data/lib/as_json_representations/version.rb +1 -1
- data/lib/as_json_representations.rb +6 -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: 8538dc805ef2b3830ae49cb42803e1ca8cfc18fd2baf5149a1c8c2d5ee804a84
|
4
|
+
data.tar.gz: 0f8fe6df1adda47ff911753e502a830d096f698f00454369393afb149bb6eb29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bf53d9de42ac55e154b462b37b032e808fcc9c42be55a2faaa2609679226c9b33306fc04e86e72e5c0e2f1be6d0e02e9d6e4cdf12f26fd5a08ebbce98053064
|
7
|
+
data.tar.gz: a718f409c924edd9e22fef11cc5b674f2d7957c38ae35c51e3d9ffe8452547cf13a6b3e222041ca647d56ea2e4c91ec6a1d2fd638930e0185179fed46acecc4d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -76,8 +76,12 @@ end
|
|
76
76
|
|
77
77
|
city = City.new('Madrid')
|
78
78
|
user = User.new('John', 'Doe', 30, city)
|
79
|
+
|
79
80
|
user.as_json(representation: :private, date: '2017-12-21')
|
80
81
|
# {:full_name=>"John Doe", :date=>"2017-12-21", :age=>30, :city=>{:name=>"Madrid"}}
|
82
|
+
|
83
|
+
user.representation(:private, date: '2017-12-21') # short form
|
84
|
+
# {:full_name=>"John Doe", :date=>"2017-12-21", :age=>30, :city=>{:name=>"Madrid"}}
|
81
85
|
```
|
82
86
|
|
83
87
|
## Development
|
@@ -10,7 +10,8 @@ module AsJsonRepresentations
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def render_representation(object, options)
|
13
|
-
|
13
|
+
name_representation = options.delete(:representation)&.to_sym
|
14
|
+
return {} unless (representation = representations[name_representation])
|
14
15
|
|
15
16
|
data = object.instance_exec(options, &representation[:block])
|
16
17
|
|
@@ -38,6 +39,10 @@ module AsJsonRepresentations
|
|
38
39
|
end
|
39
40
|
end
|
40
41
|
}
|
42
|
+
|
43
|
+
def representation(name, options={})
|
44
|
+
as_json(options.merge(representation: name))
|
45
|
+
end
|
41
46
|
end
|
42
47
|
end
|
43
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: as_json_representations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rjurado01
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|