representable 2.4.0.rc3 → 2.4.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +7 -2
  3. data/Rakefile +6 -0
  4. data/lib/representable.rb +21 -17
  5. data/lib/representable/binding.rb +3 -2
  6. data/lib/representable/definition.rb +1 -1
  7. data/lib/representable/deprecations.rb +31 -5
  8. data/lib/representable/deserializer.rb +24 -34
  9. data/lib/representable/hash/collection.rb +9 -2
  10. data/lib/representable/hash_methods.rb +2 -2
  11. data/lib/representable/parse_strategies.rb +6 -7
  12. data/lib/representable/pipeline.rb +12 -1
  13. data/lib/representable/pipeline_factories.rb +9 -2
  14. data/lib/representable/serializer.rb +3 -3
  15. data/lib/representable/version.rb +1 -1
  16. data/test-with-deprecations/as_test.rb +65 -0
  17. data/test-with-deprecations/benchmarking.rb +83 -0
  18. data/test-with-deprecations/binding_test.rb +46 -0
  19. data/test-with-deprecations/blaaaaaaaa_test.rb +69 -0
  20. data/test-with-deprecations/cached_test.rb +147 -0
  21. data/test-with-deprecations/class_test.rb +119 -0
  22. data/test-with-deprecations/coercion_test.rb +52 -0
  23. data/test-with-deprecations/config/inherit_test.rb +135 -0
  24. data/test-with-deprecations/config_test.rb +122 -0
  25. data/test-with-deprecations/decorator_scope_test.rb +28 -0
  26. data/test-with-deprecations/decorator_test.rb +96 -0
  27. data/test-with-deprecations/default_test.rb +34 -0
  28. data/test-with-deprecations/defaults_options_test.rb +93 -0
  29. data/test-with-deprecations/definition_test.rb +264 -0
  30. data/test-with-deprecations/example.rb +310 -0
  31. data/test-with-deprecations/examples/object.rb +31 -0
  32. data/test-with-deprecations/exec_context_test.rb +93 -0
  33. data/test-with-deprecations/features_test.rb +70 -0
  34. data/test-with-deprecations/filter_test.rb +57 -0
  35. data/test-with-deprecations/for_collection_test.rb +74 -0
  36. data/test-with-deprecations/generic_test.rb +116 -0
  37. data/test-with-deprecations/getter_setter_test.rb +21 -0
  38. data/test-with-deprecations/hash_bindings_test.rb +87 -0
  39. data/test-with-deprecations/hash_test.rb +160 -0
  40. data/test-with-deprecations/heritage_test.rb +62 -0
  41. data/test-with-deprecations/if_test.rb +79 -0
  42. data/test-with-deprecations/include_exclude_test.rb +88 -0
  43. data/test-with-deprecations/inherit_test.rb +159 -0
  44. data/test-with-deprecations/inline_test.rb +272 -0
  45. data/test-with-deprecations/instance_test.rb +266 -0
  46. data/test-with-deprecations/is_representable_test.rb +77 -0
  47. data/test-with-deprecations/json_test.rb +355 -0
  48. data/test-with-deprecations/lonely_test.rb +239 -0
  49. data/test-with-deprecations/mongoid_test.rb +31 -0
  50. data/test-with-deprecations/nested_test.rb +115 -0
  51. data/test-with-deprecations/object_test.rb +60 -0
  52. data/{test/---deserialize-pipeline_test.rb → test-with-deprecations/parse_pipeline_test.rb} +29 -2
  53. data/test-with-deprecations/parse_strategy_test.rb +279 -0
  54. data/{test → test-with-deprecations}/pass_options_test.rb +0 -0
  55. data/test-with-deprecations/pipeline_test.rb +277 -0
  56. data/test-with-deprecations/populator_test.rb +105 -0
  57. data/test-with-deprecations/prepare_test.rb +67 -0
  58. data/test-with-deprecations/private_options_test.rb +18 -0
  59. data/test-with-deprecations/reader_writer_test.rb +19 -0
  60. data/test-with-deprecations/realistic_benchmark.rb +115 -0
  61. data/test-with-deprecations/render_nil_test.rb +21 -0
  62. data/test-with-deprecations/represent_test.rb +88 -0
  63. data/test-with-deprecations/representable_test.rb +511 -0
  64. data/test-with-deprecations/schema_test.rb +148 -0
  65. data/test-with-deprecations/serialize_deserialize_test.rb +33 -0
  66. data/test-with-deprecations/skip_test.rb +81 -0
  67. data/test-with-deprecations/stringify_hash_test.rb +41 -0
  68. data/test-with-deprecations/test_helper.rb +135 -0
  69. data/test-with-deprecations/test_helper_test.rb +25 -0
  70. data/test-with-deprecations/uncategorized_test.rb +67 -0
  71. data/test-with-deprecations/user_options_test.rb +15 -0
  72. data/test-with-deprecations/wrap_test.rb +152 -0
  73. data/test-with-deprecations/xml_bindings_test.rb +62 -0
  74. data/test-with-deprecations/xml_test.rb +503 -0
  75. data/test-with-deprecations/yaml_test.rb +162 -0
  76. data/test/as_test.rb +3 -3
  77. data/test/cached_test.rb +2 -2
  78. data/test/class_test.rb +5 -5
  79. data/test/exec_context_test.rb +2 -2
  80. data/test/filter_test.rb +1 -1
  81. data/test/getter_setter_test.rb +4 -4
  82. data/test/if_test.rb +2 -2
  83. data/test/include_exclude_test.rb +88 -0
  84. data/test/instance_test.rb +15 -15
  85. data/test/lonely_test.rb +18 -2
  86. data/test/object_test.rb +4 -4
  87. data/test/parse_pipeline_test.rb +64 -0
  88. data/test/parse_strategy_test.rb +3 -3
  89. data/test/pipeline_test.rb +8 -12
  90. data/test/prepare_test.rb +2 -3
  91. data/test/reader_writer_test.rb +3 -3
  92. data/test/representable_test.rb +12 -48
  93. data/test/serialize_deserialize_test.rb +9 -9
  94. data/test/skip_test.rb +11 -11
  95. data/test/test_helper.rb +2 -0
  96. data/test/uncategorized_test.rb +10 -10
  97. data/test/user_options_test.rb +15 -0
  98. data/test/wrap_test.rb +1 -1
  99. metadata +65 -4
data/test/skip_test.rb CHANGED
@@ -2,14 +2,14 @@ require 'test_helper'
2
2
 
3
3
  class SkipParseTest < MiniTest::Spec
4
4
  representer! do
5
- property :title, skip_parse: lambda { |fragment, opts| opts[:skip?] and fragment == "skip me" }
5
+ property :title, skip_parse: lambda { |options| options[:user_options][:skip?] and options[:fragment] == "skip me" }
6
6
  property :band,
7
- skip_parse: lambda { |fragment, opts| opts[:skip?] and fragment["name"].nil? }, class: OpenStruct do
7
+ skip_parse: lambda { |options| options[:user_options][:skip?] and options[:fragment]["name"].nil? }, class: OpenStruct do
8
8
  property :name
9
9
  end
10
10
 
11
11
  collection :airplays,
12
- skip_parse: lambda { |fragment, opts| opts[:skip?] and fragment["station"].nil? }, class: OpenStruct do
12
+ skip_parse: lambda { |options| options[:user_options][:skip?] and options[:fragment]["station"].nil? }, class: OpenStruct do
13
13
  property :station
14
14
  end
15
15
  end
@@ -22,7 +22,7 @@ class SkipParseTest < MiniTest::Spec
22
22
  "title" => "Victim Of Fate",
23
23
  "band" => {"name" => "Mute 98"},
24
24
  "airplays" => [{"station" => "JJJ"}]
25
- }, skip?: true)
25
+ }, user_options: { skip?: true })
26
26
 
27
27
  song.title.must_equal "Victim Of Fate"
28
28
  song.band.name.must_equal "Mute 98"
@@ -37,7 +37,7 @@ class SkipParseTest < MiniTest::Spec
37
37
  "title" => "skip me",
38
38
  "band" => {},
39
39
  "airplays" => [{"station" => "JJJ"}, {}],
40
- }, skip?: true)
40
+ }, user_options: { skip?: true })
41
41
 
42
42
  song.title.must_equal nil
43
43
  song.band.must_equal nil
@@ -49,12 +49,12 @@ class SkipRenderTest < MiniTest::Spec
49
49
  representer! do
50
50
  property :title
51
51
  property :band,
52
- skip_render: lambda { |object, opts| opts[:skip?] and object.name == "Rancid" } do
52
+ skip_render: lambda { |options| options[:user_options][:skip?] and options[:input].name == "Rancid" } do
53
53
  property :name
54
54
  end
55
55
 
56
56
  collection :airplays,
57
- skip_render: lambda { |object, opts| puts object.inspect; opts[:skip?] and object.station == "Radio Dreyeckland" } do
57
+ skip_render: lambda { |options| options[:user_options][:skip?] and options[:input].station == "Radio Dreyeckland" } do
58
58
  property :station
59
59
  end
60
60
  end
@@ -63,19 +63,19 @@ class SkipRenderTest < MiniTest::Spec
63
63
  let (:skip_song) { OpenStruct.new(title: "Time Bomb", band: OpenStruct.new(name: "Rancid")).extend(representer) }
64
64
 
65
65
  # do render.
66
- it { song.to_hash(skip?: true).must_equal({"title"=>"Black Night", "band"=>{"name"=>"Time Again"}}) }
66
+ it { song.to_hash(user_options: { skip?: true }).must_equal({"title"=>"Black Night", "band"=>{"name"=>"Time Again"}}) }
67
67
  # skip.
68
- it { skip_song.to_hash(skip?: true).must_equal({"title"=>"Time Bomb"}) }
68
+ it { skip_song.to_hash(user_options: { skip?: true }).must_equal({"title"=>"Time Bomb"}) }
69
69
 
70
70
  # do render all collection items.
71
71
  it do
72
72
  song = OpenStruct.new(airplays: [OpenStruct.new(station: "JJJ"), OpenStruct.new(station: "ABC")]).extend(representer)
73
- song.to_hash(skip?: true).must_equal({"airplays"=>[{"station"=>"JJJ"}, {"station"=>"ABC"}]})
73
+ song.to_hash(user_options: { skip?: true }).must_equal({"airplays"=>[{"station"=>"JJJ"}, {"station"=>"ABC"}]})
74
74
  end
75
75
 
76
76
  # skip middle item.
77
77
  it do
78
78
  song = OpenStruct.new(airplays: [OpenStruct.new(station: "JJJ"), OpenStruct.new(station: "Radio Dreyeckland"), OpenStruct.new(station: "ABC")]).extend(representer)
79
- song.to_hash(skip?: true).must_equal({"airplays"=>[{"station"=>"JJJ"}, {"station"=>"ABC"}]})
79
+ song.to_hash(user_options: { skip?: true }).must_equal({"airplays"=>[{"station"=>"JJJ"}, {"station"=>"ABC"}]})
80
80
  end
81
81
  end
data/test/test_helper.rb CHANGED
@@ -11,6 +11,8 @@ require 'test_xml/mini_test'
11
11
 
12
12
  require "representable/debug"
13
13
 
14
+ Representable.deprecations = false
15
+
14
16
  class Album
15
17
  attr_accessor :songs, :best_song
16
18
  def initialize(songs=nil, best_song=nil)
@@ -31,17 +31,17 @@ class RenderPipelineOptionTest < MiniTest::Spec
31
31
 
32
32
  representer!(decorator: true) do
33
33
  property :id, render_pipeline: ->(input, options) do
34
- Representable::Pipeline[*render_functions.insert(2, options[:user_options][:function])]
34
+ Representable::Pipeline[*render_functions.insert(2, options[:options][:user_options][:function])]
35
35
  end
36
36
  end
37
37
 
38
- it { representer.new(Album.new).to_hash(function: NilToNA).must_equal({"id"=>"n/a"}) }
39
- it { representer.new(Album.new(1)).to_hash(function: NilToNA).must_equal({"id"=>1}) }
38
+ it { representer.new(Album.new).to_hash(user_options: {function: NilToNA}).must_equal({"id"=>"n/a"}) }
39
+ it { representer.new(Album.new(1)).to_hash(user_options: {function: NilToNA}).must_equal({"id"=>1}) }
40
40
 
41
41
  it "is cached" do
42
42
  decorator = representer.new(Album.new)
43
- decorator.to_hash(function: NilToNA).must_equal({"id"=>"n/a"})
44
- decorator.to_hash(function: nil).must_equal({"id"=>"n/a"}) # non-sense function is not applied.
43
+ decorator.to_hash(user_options: {function: NilToNA}).must_equal({"id"=>"n/a"})
44
+ decorator.to_hash(user_options: {function: nil}).must_equal({"id"=>"n/a"}) # non-sense function is not applied.
45
45
  end
46
46
 
47
47
  end
@@ -52,16 +52,16 @@ class ParsePipelineOptionTest < MiniTest::Spec
52
52
 
53
53
  representer!(decorator: true) do
54
54
  property :id, parse_pipeline: ->(input, options) do
55
- Representable::Pipeline[*parse_functions.insert(3, options[:user_options][:function])].extend(Representable::Pipeline::Debug)
55
+ Representable::Pipeline[*parse_functions.insert(3, options[:options][:user_options][:function])].extend(Representable::Pipeline::Debug)
56
56
  end
57
57
  end
58
58
 
59
- it { representer.new(Album.new).from_hash({"id"=>nil}, function: NilToNA).id.must_equal "n/a" }
60
- it { representer.new(Album.new(1)).to_hash(function: NilToNA).must_equal({"id"=>1}) }
59
+ it { representer.new(Album.new).from_hash({"id"=>nil}, user_options: {function: NilToNA}).id.must_equal "n/a" }
60
+ it { representer.new(Album.new(1)).to_hash(user_options: {function: NilToNA}).must_equal({"id"=>1}) }
61
61
 
62
62
  it "is cached" do
63
63
  decorator = representer.new(Album.new)
64
- decorator.from_hash({"id"=>nil}, function: NilToNA).id.must_equal "n/a"
65
- decorator.from_hash({"id"=>nil}, function: "nonsense").id.must_equal "n/a" # non-sense function is not applied.
64
+ decorator.from_hash({"id"=>nil}, user_options: {function: NilToNA}).id.must_equal "n/a"
65
+ decorator.from_hash({"id"=>nil}, user_options: {function: "nonsense"}).id.must_equal "n/a" # non-sense function is not applied.
66
66
  end
67
67
  end
@@ -0,0 +1,15 @@
1
+ require "test_helper"
2
+
3
+ class UserOptionsTest < Minitest::Spec
4
+ Song = Struct.new(:title)
5
+
6
+ representer! do
7
+ property :title, if: ->(options) { options[:user_options][:visible] }
8
+ end
9
+
10
+ it { Song.new("Run With It").extend(representer).to_hash.must_equal({}) }
11
+ it { Song.new("Run With It").extend(representer).to_hash(user_options: {visible: true}).must_equal({"title"=>"Run With It"}) }
12
+ it { Song.new("Run With It").extend(representer).from_hash("title"=>"Business Conduct").title.must_equal "Run With It" }
13
+ it { Song.new("Run With It").extend(representer).from_hash({"title"=>"Business Conduct"}, user_options: {visible: true}).title.must_equal "Business Conduct" }
14
+ end
15
+ # Representable.deprecations=false
data/test/wrap_test.rb CHANGED
@@ -92,7 +92,7 @@ class HashDisableWrapTest < MiniTest::Spec
92
92
 
93
93
  let (:album) { AlbumDecorator.prepare(Album.new(Band.new("Social Distortion", Label.new("Epitaph")))) }
94
94
 
95
- # band has wrap turned of per property definition, however, label still has wrap.
95
+ # band has wrap turned off per property definition, however, label still has wrap.
96
96
  it "renders" do
97
97
  album.to_hash.must_equal({"albums" => {"band" => {"name"=>"Social Distortion", "label"=>{"important"=>{"name"=>"Epitaph"}}}}})
98
98
  end
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: 2.4.0.rc3
4
+ version: 2.4.0.rc4
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-11-12 00:00:00.000000000 Z
11
+ date: 2015-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber
@@ -190,7 +190,66 @@ files:
190
190
  - lib/representable/yaml.rb
191
191
  - lib/representable/yaml/binding.rb
192
192
  - representable.gemspec
193
- - test/---deserialize-pipeline_test.rb
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
194
253
  - test/as_test.rb
195
254
  - test/benchmarking.rb
196
255
  - test/binding_test.rb
@@ -216,6 +275,7 @@ files:
216
275
  - test/hash_test.rb
217
276
  - test/heritage_test.rb
218
277
  - test/if_test.rb
278
+ - test/include_exclude_test.rb
219
279
  - test/inherit_test.rb
220
280
  - test/inline_test.rb
221
281
  - test/instance_test.rb
@@ -225,8 +285,8 @@ files:
225
285
  - test/mongoid_test.rb
226
286
  - test/nested_test.rb
227
287
  - test/object_test.rb
288
+ - test/parse_pipeline_test.rb
228
289
  - test/parse_strategy_test.rb
229
- - test/pass_options_test.rb
230
290
  - test/pipeline_test.rb
231
291
  - test/populator_test.rb
232
292
  - test/prepare_test.rb
@@ -243,6 +303,7 @@ files:
243
303
  - test/test_helper.rb
244
304
  - test/test_helper_test.rb
245
305
  - test/uncategorized_test.rb
306
+ - test/user_options_test.rb
246
307
  - test/wrap_test.rb
247
308
  - test/xml_bindings_test.rb
248
309
  - test/xml_test.rb