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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d7ce0e4ea64715ea7104e752ce7a5e19ae965cb65dcd5c771a677224578e1e6
4
- data.tar.gz: fcefce4937dfb9ffc67723f7f263f81ca1f13cbe7ecbf152bc174b4713110c38
3
+ metadata.gz: 8538dc805ef2b3830ae49cb42803e1ca8cfc18fd2baf5149a1c8c2d5ee804a84
4
+ data.tar.gz: 0f8fe6df1adda47ff911753e502a830d096f698f00454369393afb149bb6eb29
5
5
  SHA512:
6
- metadata.gz: 179b536f2bd9c3f2cfea67f97dcfae09d827e1cebf9dd10f0702145ce2a0fe61ddd921f0285e625446e30fe93bd13d64a4aa4c9498d89dd4aafc3a999e87745a
7
- data.tar.gz: e7d6806a997899b7b10cb90b33a6563151c840579b65ccda89c0e59997d09e98a53574b54f99889c3b163b40385ffa1a52f9f2d21337bbad35de3a67add9f55a
6
+ metadata.gz: 3bf53d9de42ac55e154b462b37b032e808fcc9c42be55a2faaa2609679226c9b33306fc04e86e72e5c0e2f1be6d0e02e9d6e4cdf12f26fd5a08ebbce98053064
7
+ data.tar.gz: a718f409c924edd9e22fef11cc5b674f2d7957c38ae35c51e3d9ffe8452547cf13a6b3e222041ca647d56ea2e4c91ec6a1d2fd638930e0185179fed46acecc4d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- as_json_representations (0.2.0)
4
+ as_json_representations (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -32,4 +32,4 @@ DEPENDENCIES
32
32
  rspec (~> 3.0)
33
33
 
34
34
  BUNDLED WITH
35
- 1.16.1
35
+ 1.16.2
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
@@ -1,3 +1,3 @@
1
1
  module AsJsonRepresentations
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -10,7 +10,8 @@ module AsJsonRepresentations
10
10
  end
11
11
 
12
12
  def render_representation(object, options)
13
- return {} unless (representation = representations[options.delete :representation])
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.2.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-01-25 00:00:00.000000000 Z
11
+ date: 2018-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler