upholsterer 0.4.5 → 0.5.0
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/Gemfile.lock +1 -1
- data/lib/upholsterer/base.rb +18 -14
- data/lib/upholsterer/json_presenter.rb +13 -4
- data/lib/upholsterer/version.rb +2 -2
- data/spec/base_spec.rb +8 -0
- data/spec/support/serializable_presenter.rb +19 -0
- data/{simple_presenter.gemspec → upholsterer.gemspec} +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dba9d573261b59fac0cbeb4d5e84a4d8b86b82bc
|
4
|
+
data.tar.gz: 12dc5ee6b0c8dec15e33bebb00420338eb770c88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec15e2d7913c8df58739b39256f8b8bd8286b9790498bba0528abffc79a52df11c4be1c066a49dc0d2e67898bf9a6e28148a5a47c8a6e73ac1d12c13f8a97414
|
7
|
+
data.tar.gz: 870195e092a9ab36dccd7e65defb97b66d4ce3d30ecae610331c9e87d54310e8436ef0fbed329a61fa7066c285396620c6c903a4bad2dc3f7847cd6f504682a6
|
data/Gemfile.lock
CHANGED
data/lib/upholsterer/base.rb
CHANGED
@@ -128,21 +128,25 @@ module Upholsterer
|
|
128
128
|
end
|
129
129
|
|
130
130
|
attrs.each do |attr_name|
|
131
|
-
|
132
|
-
|
133
|
-
options.fetch(:as, attr_name)
|
134
|
-
].compact.join('_')
|
135
|
-
|
136
|
-
attributes[method_name.to_sym] = [attr_name, options]
|
137
|
-
|
138
|
-
if block_given? and container.present?
|
139
|
-
delegate attr_name, to: wrapper_method, prefix: !!method_prefix
|
131
|
+
if options.fetch(:serializable, false)
|
132
|
+
attributes[attr_name] = [attr_name, options]
|
140
133
|
else
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
134
|
+
method_name = [
|
135
|
+
method_prefix,
|
136
|
+
options.fetch(:as, attr_name)
|
137
|
+
].compact.join('_')
|
138
|
+
|
139
|
+
attributes[method_name.to_sym] = [attr_name, options]
|
140
|
+
|
141
|
+
if block_given? and container.present?
|
142
|
+
delegate attr_name, to: wrapper_method, prefix: !!method_prefix
|
143
|
+
else
|
144
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
145
|
+
def #{method_name}(&block) # def user_name(&block)
|
146
|
+
proxy_message(#{container.inspect}, "#{attr_name}", &block) # proxy_message("user", "name")
|
147
|
+
end # end
|
148
|
+
RUBY
|
149
|
+
end
|
146
150
|
end
|
147
151
|
end
|
148
152
|
end
|
@@ -4,6 +4,12 @@ module Upholsterer
|
|
4
4
|
class Base
|
5
5
|
delegate :to_json, :as_json, to: :to_hash, prefix: false
|
6
6
|
|
7
|
+
def self.serializable(*args)
|
8
|
+
args.each do |method_name|
|
9
|
+
attributes[method_name.to_sym] = [method_name.to_sym, { serializable: true }]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
7
13
|
def to_hash
|
8
14
|
Hash[json_fields.collect do |field|
|
9
15
|
[field, public_send(field)]
|
@@ -15,10 +21,13 @@ module Upholsterer
|
|
15
21
|
private
|
16
22
|
|
17
23
|
def json_fields
|
18
|
-
@json_fields ||=
|
19
|
-
|
20
|
-
|
21
|
-
|
24
|
+
@json_fields ||= begin
|
25
|
+
methods = public_methods(false).tap do |fields|
|
26
|
+
fields.delete(:subject)
|
27
|
+
fields.delete(:respond_to?)
|
28
|
+
fields.delete(:method_missing)
|
29
|
+
end
|
30
|
+
(methods + self.class.attributes.keys).uniq
|
22
31
|
end
|
23
32
|
end
|
24
33
|
end
|
data/lib/upholsterer/version.rb
CHANGED
data/spec/base_spec.rb
CHANGED
@@ -186,6 +186,14 @@ describe Upholsterer::Base do
|
|
186
186
|
it { should eq '{}' }
|
187
187
|
end
|
188
188
|
|
189
|
+
describe 'serializable' do
|
190
|
+
describe 'with inheritance' do
|
191
|
+
subject { SerializablePresenter.new(double).to_json }
|
192
|
+
|
193
|
+
it { should eq '{"one":1,"two":2}'}
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
189
197
|
describe 'expose with block' do
|
190
198
|
let(:project) { double id: 1, description: 'description', type: 'type' }
|
191
199
|
subject { CollectPresenter.new(entity) }
|
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ['Nando Vieira', 'Aleksandr Fomin', 'Gleb Sinyavsky']
|
10
10
|
s.email = ['fnando.vieira@gmail.com', 'll.wg.bin@gmail.com']
|
11
|
-
s.homepage = 'https://github.com/
|
11
|
+
s.homepage = 'https://github.com/Archistart/upholsterer'
|
12
12
|
s.summary = 'A simple presenter/facade/decorator/whatever implementation.'
|
13
13
|
s.description = s.summary
|
14
14
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: upholsterer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2015-05-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -89,7 +89,6 @@ files:
|
|
89
89
|
- lib/upholsterer/rails.rb
|
90
90
|
- lib/upholsterer/url_methods.rb
|
91
91
|
- lib/upholsterer/version.rb
|
92
|
-
- simple_presenter.gemspec
|
93
92
|
- spec/base_spec.rb
|
94
93
|
- spec/spec_helper.rb
|
95
94
|
- spec/support/alias_presenter.rb
|
@@ -99,10 +98,12 @@ files:
|
|
99
98
|
- spec/support/expose_all_presenter.rb
|
100
99
|
- spec/support/iterator_presenter.rb
|
101
100
|
- spec/support/matchers/json_matcher.rb
|
101
|
+
- spec/support/serializable_presenter.rb
|
102
102
|
- spec/support/user.rb
|
103
103
|
- spec/support/user_presenter.rb
|
104
104
|
- spec/upholsterer_spec.rb
|
105
|
-
|
105
|
+
- upholsterer.gemspec
|
106
|
+
homepage: https://github.com/Archistart/upholsterer
|
106
107
|
licenses: []
|
107
108
|
metadata: {}
|
108
109
|
post_install_message:
|