representable 2.4.1 → 3.0.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/.travis.yml +7 -12
- data/CHANGES.md +6 -27
- data/README.md +28 -1326
- data/lib/representable.rb +4 -14
- data/lib/representable/binding.rb +3 -7
- data/lib/representable/definition.rb +1 -2
- data/lib/representable/populator.rb +35 -0
- data/lib/representable/version.rb +1 -1
- data/test/definition_test.rb +0 -7
- data/test/exec_context_test.rb +2 -2
- data/test/instance_test.rb +0 -19
- data/test/realistic_benchmark.rb +0 -13
- data/test/representable_test.rb +0 -16
- data/test/skip_test.rb +1 -1
- data/test/test_helper.rb +0 -2
- metadata +3 -65
- data/lib/representable/deprecations.rb +0 -127
- data/lib/representable/parse_strategies.rb +0 -93
- data/test-with-deprecations/as_test.rb +0 -65
- data/test-with-deprecations/benchmarking.rb +0 -83
- data/test-with-deprecations/binding_test.rb +0 -46
- data/test-with-deprecations/blaaaaaaaa_test.rb +0 -69
- data/test-with-deprecations/cached_test.rb +0 -147
- data/test-with-deprecations/class_test.rb +0 -119
- data/test-with-deprecations/coercion_test.rb +0 -52
- data/test-with-deprecations/config/inherit_test.rb +0 -135
- data/test-with-deprecations/config_test.rb +0 -122
- data/test-with-deprecations/decorator_scope_test.rb +0 -28
- data/test-with-deprecations/decorator_test.rb +0 -96
- data/test-with-deprecations/default_test.rb +0 -34
- data/test-with-deprecations/defaults_options_test.rb +0 -93
- data/test-with-deprecations/definition_test.rb +0 -264
- data/test-with-deprecations/example.rb +0 -310
- data/test-with-deprecations/examples/object.rb +0 -31
- data/test-with-deprecations/exec_context_test.rb +0 -93
- data/test-with-deprecations/features_test.rb +0 -70
- data/test-with-deprecations/filter_test.rb +0 -57
- data/test-with-deprecations/for_collection_test.rb +0 -74
- data/test-with-deprecations/generic_test.rb +0 -116
- data/test-with-deprecations/getter_setter_test.rb +0 -21
- data/test-with-deprecations/hash_bindings_test.rb +0 -87
- data/test-with-deprecations/hash_test.rb +0 -160
- data/test-with-deprecations/heritage_test.rb +0 -62
- data/test-with-deprecations/if_test.rb +0 -79
- data/test-with-deprecations/include_exclude_test.rb +0 -88
- data/test-with-deprecations/inherit_test.rb +0 -159
- data/test-with-deprecations/inline_test.rb +0 -272
- data/test-with-deprecations/instance_test.rb +0 -266
- data/test-with-deprecations/is_representable_test.rb +0 -77
- data/test-with-deprecations/json_test.rb +0 -355
- data/test-with-deprecations/lonely_test.rb +0 -239
- data/test-with-deprecations/mongoid_test.rb +0 -31
- data/test-with-deprecations/nested_test.rb +0 -115
- data/test-with-deprecations/object_test.rb +0 -60
- data/test-with-deprecations/parse_pipeline_test.rb +0 -64
- data/test-with-deprecations/parse_strategy_test.rb +0 -279
- data/test-with-deprecations/pass_options_test.rb +0 -27
- data/test-with-deprecations/pipeline_test.rb +0 -277
- data/test-with-deprecations/populator_test.rb +0 -105
- data/test-with-deprecations/prepare_test.rb +0 -67
- data/test-with-deprecations/private_options_test.rb +0 -18
- data/test-with-deprecations/reader_writer_test.rb +0 -19
- data/test-with-deprecations/realistic_benchmark.rb +0 -115
- data/test-with-deprecations/render_nil_test.rb +0 -21
- data/test-with-deprecations/represent_test.rb +0 -88
- data/test-with-deprecations/representable_test.rb +0 -511
- data/test-with-deprecations/schema_test.rb +0 -148
- data/test-with-deprecations/serialize_deserialize_test.rb +0 -33
- data/test-with-deprecations/skip_test.rb +0 -81
- data/test-with-deprecations/stringify_hash_test.rb +0 -41
- data/test-with-deprecations/test_helper.rb +0 -135
- data/test-with-deprecations/test_helper_test.rb +0 -25
- data/test-with-deprecations/uncategorized_test.rb +0 -67
- data/test-with-deprecations/user_options_test.rb +0 -15
- data/test-with-deprecations/wrap_test.rb +0 -152
- data/test-with-deprecations/xml_bindings_test.rb +0 -62
- data/test-with-deprecations/xml_test.rb +0 -503
- data/test-with-deprecations/yaml_test.rb +0 -162
- data/test/parse_strategy_test.rb +0 -279
data/lib/representable.rb
CHANGED
@@ -73,11 +73,9 @@ private
|
|
73
73
|
representable_attrs.collect {|definition| format.build(definition) }
|
74
74
|
end
|
75
75
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
{user_options: {}}.merge(options) # TODO: use keyword args once we drop 2.0.
|
80
|
-
end
|
76
|
+
def normalize_options(options)
|
77
|
+
return options if options.any?
|
78
|
+
{user_options: {}}.merge(options) # TODO: use keyword args once we drop 2.0.
|
81
79
|
end
|
82
80
|
|
83
81
|
# Prepares options for a particular nested representer.
|
@@ -120,15 +118,7 @@ private
|
|
120
118
|
end
|
121
119
|
end
|
122
120
|
|
123
|
-
require "representable/deprecations"
|
124
|
-
def self.deprecations=(value)
|
125
|
-
evaluator = value==false ? Binding::EvaluateOption : Binding::Deprecation::EvaluateOption
|
126
|
-
::Representable::Binding.send :include, evaluator
|
127
|
-
|
128
|
-
evaluator = value==false ? NormalizeOptions : Deprecation::NormalizeOptions
|
129
|
-
::Representable.send :include, evaluator
|
130
|
-
end
|
131
|
-
self.deprecations = true # TODO: change to false in 2.5 or remove entirely.
|
121
|
+
# require "representable/deprecations"
|
132
122
|
end
|
133
123
|
|
134
124
|
require 'representable/autoload'
|
@@ -6,13 +6,9 @@ module Representable
|
|
6
6
|
class FragmentNotFound
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
return definition.create_binding if definition[:binding]
|
12
|
-
build_for(definition)
|
13
|
-
end
|
9
|
+
def self.build(definition)
|
10
|
+
build_for(definition)
|
14
11
|
end
|
15
|
-
extend ClassDeprecatable
|
16
12
|
|
17
13
|
def initialize(definition)
|
18
14
|
@definition = definition
|
@@ -50,7 +46,7 @@ module Representable
|
|
50
46
|
proc.(send(:exec_context, options), options.merge(user_options: options[:options][:user_options], input: input)) # from Uber::Options::Value. # NOTE: this can also be the Proc object if it's not wrapped by Uber:::Value.
|
51
47
|
end
|
52
48
|
end
|
53
|
-
|
49
|
+
include EvaluateOption
|
54
50
|
|
55
51
|
def [](name)
|
56
52
|
@definition[name]
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require "uber/options"
|
2
|
-
require "representable/
|
2
|
+
require "representable/populator"
|
3
3
|
|
4
4
|
module Representable
|
5
5
|
# Created at class compile time. Keeps configuration options for one property.
|
@@ -88,7 +88,6 @@ module Representable
|
|
88
88
|
handle_as!(options)
|
89
89
|
|
90
90
|
# DISCUSS: we could call more macros here (e.g. for :nested).
|
91
|
-
Representable::ParseStrategy.apply!(options)
|
92
91
|
Representable::Populator.apply!(options)
|
93
92
|
|
94
93
|
yield options if block_given?
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Representable
|
2
|
+
class Populator
|
3
|
+
FindOrInstantiate = ->(input, options) {
|
4
|
+
binding = options[:binding]
|
5
|
+
|
6
|
+
object_class = binding[:class].(input, options)
|
7
|
+
object = object_class.find_by(id: input["id"]) || object_class.new
|
8
|
+
if options[:binding].array?
|
9
|
+
# represented.songs[i] = model
|
10
|
+
options[:represented].send(binding.getter)[options[:index]] = object
|
11
|
+
else
|
12
|
+
# represented.song = model
|
13
|
+
options[:represented].send(binding.setter, object)
|
14
|
+
end
|
15
|
+
|
16
|
+
object
|
17
|
+
}
|
18
|
+
|
19
|
+
# pipeline: [StopOnExcluded, AssignName, ReadFragment, StopOnNotFound, OverwriteOnNil, AssignFragment, #<Representable::Function::CreateObject:0x9805a44>, #<Representable::Function::Decorate:0x9805a1c>, Deserialize, Set]
|
20
|
+
|
21
|
+
def self.apply!(options)
|
22
|
+
return unless populator = options[:populator]
|
23
|
+
|
24
|
+
options[:parse_pipeline] = ->(input, options) do
|
25
|
+
pipeline = Pipeline[*parse_functions] # TODO: AssignFragment
|
26
|
+
pipeline = Pipeline::Insert.(pipeline, SetValue, delete: true) # remove the setter function.
|
27
|
+
pipeline = Pipeline::Insert.(pipeline, populator, replace: CreateObject::Populator) # let the actual populator do the job.
|
28
|
+
# puts pipeline.extend(Representable::Pipeline::Debug).inspect
|
29
|
+
pipeline
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
FindOrInstantiate = Populator::FindOrInstantiate
|
35
|
+
end
|
data/test/definition_test.rb
CHANGED
@@ -43,13 +43,6 @@ class DefinitionTest < MiniTest::Spec
|
|
43
43
|
# override original when passed in #merge!.
|
44
44
|
it { definition.merge!({:whatever => false})[:whatever].must_equal false }
|
45
45
|
|
46
|
-
|
47
|
-
it "runs macros" do
|
48
|
-
definition[:setter].must_equal nil
|
49
|
-
definition.merge!(:parse_strategy => :sync)
|
50
|
-
definition[:setter].must_respond_to :evaluate
|
51
|
-
end
|
52
|
-
|
53
46
|
# with block
|
54
47
|
it do
|
55
48
|
definition = Definition.new(:song, :extend => Module).merge!({:something => true}) do |options|
|
data/test/exec_context_test.rb
CHANGED
@@ -36,7 +36,7 @@ class ExecContextTest < MiniTest::Spec
|
|
36
36
|
property :name,
|
37
37
|
:as => lambda { |*| self.class }, # to actually test
|
38
38
|
:exec_context => :binding,
|
39
|
-
:setter => lambda { |options| represented.name = options[:fragment] # to make parsing work.
|
39
|
+
:setter => lambda { |options| options[:represented].name = options[:fragment] # to make parsing work.
|
40
40
|
}
|
41
41
|
end
|
42
42
|
|
@@ -81,7 +81,7 @@ class ExecContextTest < MiniTest::Spec
|
|
81
81
|
property :name,
|
82
82
|
:as => lambda { |*| self.class }, # to actually test
|
83
83
|
:exec_context => :binding,
|
84
|
-
:setter => lambda { |options| represented.name = options[:fragment ] # to make parsing work.
|
84
|
+
:setter => lambda { |options| options[:represented].name = options[:fragment ] # to make parsing work.
|
85
85
|
}
|
86
86
|
end
|
87
87
|
|
data/test/instance_test.rb
CHANGED
@@ -244,23 +244,4 @@ class InstanceTest < BaseTest
|
|
244
244
|
songs.object_id.wont_equal album.songs.object_id
|
245
245
|
}
|
246
246
|
end
|
247
|
-
|
248
|
-
|
249
|
-
describe "new syntax for instance: true" do
|
250
|
-
representer!(:inject => :song_representer) do
|
251
|
-
property :song, :pass_options => true,
|
252
|
-
:extend => song_representer, :instance => lambda { |options| options[:binding].get(represented: options[:represented]) }
|
253
|
-
end
|
254
|
-
|
255
|
-
it "uses Binding#get instead of creating an instance, but deprecates" do
|
256
|
-
album= Struct.new(:song).new(song = Song.new(1, "The Answer Is Still No"))
|
257
|
-
|
258
|
-
album.
|
259
|
-
extend(representer).
|
260
|
-
from_hash("song" => {"title" => "Invincible"}).
|
261
|
-
song.must_equal Song.new(1, "Invincible")
|
262
|
-
|
263
|
-
album.song.object_id.must_equal song.object_id
|
264
|
-
end
|
265
|
-
end
|
266
247
|
end
|
data/test/realistic_benchmark.rb
CHANGED
@@ -1,19 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'benchmark'
|
3
3
|
|
4
|
-
Kernel.class_eval do
|
5
|
-
# def respond_to_missing?
|
6
|
-
# raise
|
7
|
-
# end
|
8
|
-
# alias_method :orig_hash, :hash
|
9
|
-
# def hash
|
10
|
-
# puts "hash in #{self.class}"
|
11
|
-
# raise self.inspect if self.class == Symbol
|
12
|
-
# orig_hash
|
13
|
-
# end
|
14
|
-
end
|
15
|
-
Representable.deprecations = false
|
16
|
-
|
17
4
|
SONG_PROPERTIES = 50.times.collect do |i|
|
18
5
|
"song_property_#{i}"
|
19
6
|
end
|
data/test/representable_test.rb
CHANGED
@@ -460,22 +460,6 @@ class RepresentableTest < MiniTest::Spec
|
|
460
460
|
end
|
461
461
|
end
|
462
462
|
|
463
|
-
describe ":binding" do
|
464
|
-
representer! do
|
465
|
-
class MyBinding < Representable::Binding
|
466
|
-
def write(doc, *args)
|
467
|
-
doc[:title] = represented.title
|
468
|
-
end
|
469
|
-
end
|
470
|
-
property :title, :binding => lambda { |*args| MyBinding.new(*args) }
|
471
|
-
end
|
472
|
-
|
473
|
-
it "uses the specified binding instance" do
|
474
|
-
OpenStruct.new(:title => "Affliction").extend(representer).to_hash.must_equal({:title => "Affliction"})
|
475
|
-
end
|
476
|
-
end
|
477
|
-
|
478
|
-
|
479
463
|
# TODO: Move to global place since it's used twice.
|
480
464
|
class SongRepresentation < Representable::Decorator
|
481
465
|
include Representable::JSON
|
data/test/skip_test.rb
CHANGED
@@ -36,7 +36,7 @@ class SkipParseTest < MiniTest::Spec
|
|
36
36
|
song.from_hash({
|
37
37
|
"title" => "skip me",
|
38
38
|
"band" => {},
|
39
|
-
"airplays" => [{"station" => "JJJ"}, {}],
|
39
|
+
"airplays" => [{}, {"station" => "JJJ"}, {}],
|
40
40
|
}, user_options: { skip?: true })
|
41
41
|
|
42
42
|
song.title.must_equal nil
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: representable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uber
|
@@ -163,7 +163,6 @@ files:
|
|
163
163
|
- lib/representable/declarative.rb
|
164
164
|
- lib/representable/decorator.rb
|
165
165
|
- lib/representable/definition.rb
|
166
|
-
- lib/representable/deprecations.rb
|
167
166
|
- lib/representable/deserializer.rb
|
168
167
|
- lib/representable/for_collection.rb
|
169
168
|
- lib/representable/hash.rb
|
@@ -177,9 +176,9 @@ files:
|
|
177
176
|
- lib/representable/json/hash.rb
|
178
177
|
- lib/representable/object.rb
|
179
178
|
- lib/representable/object/binding.rb
|
180
|
-
- lib/representable/parse_strategies.rb
|
181
179
|
- lib/representable/pipeline.rb
|
182
180
|
- lib/representable/pipeline_factories.rb
|
181
|
+
- lib/representable/populator.rb
|
183
182
|
- lib/representable/represent.rb
|
184
183
|
- lib/representable/serializer.rb
|
185
184
|
- lib/representable/version.rb
|
@@ -190,66 +189,6 @@ files:
|
|
190
189
|
- lib/representable/yaml.rb
|
191
190
|
- lib/representable/yaml/binding.rb
|
192
191
|
- representable.gemspec
|
193
|
-
- test-with-deprecations/as_test.rb
|
194
|
-
- test-with-deprecations/benchmarking.rb
|
195
|
-
- test-with-deprecations/binding_test.rb
|
196
|
-
- test-with-deprecations/blaaaaaaaa_test.rb
|
197
|
-
- test-with-deprecations/cached_test.rb
|
198
|
-
- test-with-deprecations/class_test.rb
|
199
|
-
- test-with-deprecations/coercion_test.rb
|
200
|
-
- test-with-deprecations/config/inherit_test.rb
|
201
|
-
- test-with-deprecations/config_test.rb
|
202
|
-
- test-with-deprecations/decorator_scope_test.rb
|
203
|
-
- test-with-deprecations/decorator_test.rb
|
204
|
-
- test-with-deprecations/default_test.rb
|
205
|
-
- test-with-deprecations/defaults_options_test.rb
|
206
|
-
- test-with-deprecations/definition_test.rb
|
207
|
-
- test-with-deprecations/example.rb
|
208
|
-
- test-with-deprecations/examples/object.rb
|
209
|
-
- test-with-deprecations/exec_context_test.rb
|
210
|
-
- test-with-deprecations/features_test.rb
|
211
|
-
- test-with-deprecations/filter_test.rb
|
212
|
-
- test-with-deprecations/for_collection_test.rb
|
213
|
-
- test-with-deprecations/generic_test.rb
|
214
|
-
- test-with-deprecations/getter_setter_test.rb
|
215
|
-
- test-with-deprecations/hash_bindings_test.rb
|
216
|
-
- test-with-deprecations/hash_test.rb
|
217
|
-
- test-with-deprecations/heritage_test.rb
|
218
|
-
- test-with-deprecations/if_test.rb
|
219
|
-
- test-with-deprecations/include_exclude_test.rb
|
220
|
-
- test-with-deprecations/inherit_test.rb
|
221
|
-
- test-with-deprecations/inline_test.rb
|
222
|
-
- test-with-deprecations/instance_test.rb
|
223
|
-
- test-with-deprecations/is_representable_test.rb
|
224
|
-
- test-with-deprecations/json_test.rb
|
225
|
-
- test-with-deprecations/lonely_test.rb
|
226
|
-
- test-with-deprecations/mongoid_test.rb
|
227
|
-
- test-with-deprecations/nested_test.rb
|
228
|
-
- test-with-deprecations/object_test.rb
|
229
|
-
- test-with-deprecations/parse_pipeline_test.rb
|
230
|
-
- test-with-deprecations/parse_strategy_test.rb
|
231
|
-
- test-with-deprecations/pass_options_test.rb
|
232
|
-
- test-with-deprecations/pipeline_test.rb
|
233
|
-
- test-with-deprecations/populator_test.rb
|
234
|
-
- test-with-deprecations/prepare_test.rb
|
235
|
-
- test-with-deprecations/private_options_test.rb
|
236
|
-
- test-with-deprecations/reader_writer_test.rb
|
237
|
-
- test-with-deprecations/realistic_benchmark.rb
|
238
|
-
- test-with-deprecations/render_nil_test.rb
|
239
|
-
- test-with-deprecations/represent_test.rb
|
240
|
-
- test-with-deprecations/representable_test.rb
|
241
|
-
- test-with-deprecations/schema_test.rb
|
242
|
-
- test-with-deprecations/serialize_deserialize_test.rb
|
243
|
-
- test-with-deprecations/skip_test.rb
|
244
|
-
- test-with-deprecations/stringify_hash_test.rb
|
245
|
-
- test-with-deprecations/test_helper.rb
|
246
|
-
- test-with-deprecations/test_helper_test.rb
|
247
|
-
- test-with-deprecations/uncategorized_test.rb
|
248
|
-
- test-with-deprecations/user_options_test.rb
|
249
|
-
- test-with-deprecations/wrap_test.rb
|
250
|
-
- test-with-deprecations/xml_bindings_test.rb
|
251
|
-
- test-with-deprecations/xml_test.rb
|
252
|
-
- test-with-deprecations/yaml_test.rb
|
253
192
|
- test/as_test.rb
|
254
193
|
- test/benchmarking.rb
|
255
194
|
- test/binding_test.rb
|
@@ -286,7 +225,6 @@ files:
|
|
286
225
|
- test/nested_test.rb
|
287
226
|
- test/object_test.rb
|
288
227
|
- test/parse_pipeline_test.rb
|
289
|
-
- test/parse_strategy_test.rb
|
290
228
|
- test/pipeline_test.rb
|
291
229
|
- test/populator_test.rb
|
292
230
|
- test/prepare_test.rb
|
@@ -1,127 +0,0 @@
|
|
1
|
-
# WARNING: this will be removed in 3.0.
|
2
|
-
module Representable::Deprecation
|
3
|
-
module NormalizeOptions
|
4
|
-
def normalize_options(options)
|
5
|
-
|
6
|
-
unless options.any?
|
7
|
-
options[:user_options] = {}
|
8
|
-
return options
|
9
|
-
end
|
10
|
-
|
11
|
-
options = options.dup
|
12
|
-
|
13
|
-
user_option_keys = options.keys - [:doc, :exclude, :include, :wrap, :user_options, * representable_attrs.keys.map(&:to_sym)]
|
14
|
-
if user_option_keys.any?
|
15
|
-
user_options = {}
|
16
|
-
warn "[Representable] Mixing user and representable options is deprecated. Please provide your options via :user_options."
|
17
|
-
user_option_keys.each { |key| user_options[key] = options.delete(key) }
|
18
|
-
options[:user_options] = user_options
|
19
|
-
end
|
20
|
-
|
21
|
-
options # {user_options: {..}, include: [], wrap: "song", artist: {..}}
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
module Representable::Binding::Deprecation
|
27
|
-
module Build
|
28
|
-
def build(definition)
|
29
|
-
warn "[Representable] The :binding option is deprecated and will be removed in 3.0. Please use your own pipeline instead." if definition[:binding]
|
30
|
-
super
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
Options = Struct.new(:binding, :user_options, :represented, :decorator)
|
35
|
-
|
36
|
-
module EvaluateOption
|
37
|
-
def self.included(includer)
|
38
|
-
super
|
39
|
-
includer.extend(Build)
|
40
|
-
end
|
41
|
-
|
42
|
-
def evaluate_option(name, input=nil, options={})
|
43
|
-
return evaluate_option_with_deprecation(name, input, options, :user_options) if name==:as
|
44
|
-
return evaluate_option_with_deprecation(name, input, options, :user_options) if name==:if
|
45
|
-
return evaluate_option_with_deprecation(name, input, options, :user_options) if name==:getter
|
46
|
-
return evaluate_option_with_deprecation(name, input, options, :doc, :user_options) if name==:writer
|
47
|
-
return evaluate_option_with_deprecation(name, input, options, :input, :user_options) if name==:skip_render
|
48
|
-
return evaluate_option_with_deprecation(name, input, options, :input, :user_options) if name==:skip_parse
|
49
|
-
return evaluate_option_with_deprecation(name, input, options, :input, :user_options) if name==:serialize
|
50
|
-
return evaluate_option_with_deprecation(name, input, options, :doc, :user_options) if name==:reader
|
51
|
-
return evaluate_option_with_deprecation(name, input, options, :input, :index, :user_options) if name==:instance
|
52
|
-
return evaluate_option_with_deprecation(name, input, options, :input, :index, :user_options) if name==:class
|
53
|
-
return evaluate_option_with_deprecation(name, input, options, :input, :fragment, :user_options) if name==:deserialize
|
54
|
-
return evaluate_option_with_deprecation(name, input, options, :input, :user_options) if name==:prepare
|
55
|
-
return evaluate_option_with_deprecation(name, input, options, :input, :user_options) if name==:extend
|
56
|
-
return evaluate_option_with_deprecation(name, input, options, :input, :user_options) if name==:setter
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
def evaluate_option_with_deprecation(name, input, options, *positional_arguments)
|
61
|
-
unless proc = self[name]
|
62
|
-
return # FIXME: why do we need this?
|
63
|
-
end
|
64
|
-
|
65
|
-
options[:input] = input
|
66
|
-
|
67
|
-
|
68
|
-
__options = if self[:pass_options]
|
69
|
-
warn %{[Representable] The :pass_options option is deprecated. Please access environment objects via options[:binding].
|
70
|
-
Learn more here: http://trailblazerb.org/gems/representable/upgrading-guide.html#pass-options}
|
71
|
-
|
72
|
-
|
73
|
-
options[:options] ||= {}
|
74
|
-
Options.new(self, options[:options][:user_options], options[:represented], options[:decorator])
|
75
|
-
else
|
76
|
-
# user_options
|
77
|
-
options[:options][:user_options] || {}
|
78
|
-
end
|
79
|
-
|
80
|
-
if proc.send(:proc?) or proc.send(:method?)
|
81
|
-
arity = proc.instance_variable_get(:@value).arity if proc.send(:proc?)
|
82
|
-
arity = send(:exec_context, options).method(proc.instance_variable_get(:@value)).arity if proc.send(:method?)
|
83
|
-
if arity != 1 or name==:getter or name==:if or name==:as
|
84
|
-
warn %{[Representable] Positional arguments for `:#{name}` are deprecated. Please use options or keyword arguments.
|
85
|
-
#{name}: ->(options) { options[:#{positional_arguments.join(" | :")}] } or
|
86
|
-
#{name}: ->(#{positional_arguments.join(":, ")}:) { }
|
87
|
-
Learn more here: http://trailblazerb.org/gems/representable/upgrading-guide.html#positional-arguments
|
88
|
-
}
|
89
|
-
deprecated_args = []
|
90
|
-
positional_arguments.each do |arg|
|
91
|
-
next if arg == :index && options[:index].nil?
|
92
|
-
deprecated_args << __options and next if arg == :user_options# either hash or Options object.
|
93
|
-
deprecated_args << options[arg]
|
94
|
-
end
|
95
|
-
return proc.(send(:exec_context, options), *deprecated_args)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
proc.(send(:exec_context, options), options.merge(user_options: options[:options][:user_options]))
|
100
|
-
end
|
101
|
-
private :evaluate_option_with_deprecation
|
102
|
-
|
103
|
-
|
104
|
-
def represented
|
105
|
-
warn "[Representable] Binding#represented is deprecated. Use options[:represented] instead."
|
106
|
-
@represented
|
107
|
-
end
|
108
|
-
|
109
|
-
def compile_fragment(options)
|
110
|
-
@represented = options[:represented]
|
111
|
-
@parent_decorator = options[:decorator]
|
112
|
-
super
|
113
|
-
end
|
114
|
-
|
115
|
-
# Parse value from doc and update the model property.
|
116
|
-
def uncompile_fragment(options)
|
117
|
-
@represented = options[:represented]
|
118
|
-
@parent_decorator = options[:decorator]
|
119
|
-
super
|
120
|
-
end
|
121
|
-
|
122
|
-
def get(options={}) # DISCUSS: evluate if we really need this.
|
123
|
-
warn "[Representable] Binding#get is deprecated."
|
124
|
-
self[:getter] ? Representable::Getter.(nil, options.merge(binding: self)) : Representable::GetValue.(nil, options.merge(binding: self))
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|