representable 2.2.2 → 2.2.3

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
  SHA1:
3
- metadata.gz: b9d4b0e0fd7f3c2d7f94d5b95ed61118ec72eeed
4
- data.tar.gz: e08e6250812c65c6206b5b3d0e64c43996262289
3
+ metadata.gz: 700ffc8c90d1f0c6b824d39a42b8af702967f2f2
4
+ data.tar.gz: e593985cdb6e362606b6d4dce794f5b6b4c7af50
5
5
  SHA512:
6
- metadata.gz: a32f69c330b3e7809a7cdb136d7510beaf78fe59e2157a415e2e0fdcedf3fb09230bc009465ac9407d5870214bfd3b2780e0ca13417e0abce34c73a9fe9ef136
7
- data.tar.gz: a0f4b545d84a68432a0738bd5ad2e9ff7597d4122852c66757e0a5b49d412500c694d274a0bf5e2c8c1f69ac2c7faec00f63a658e8c0067bea10b56c1b0c5048
6
+ metadata.gz: fb0bd53d3eb6750f5ec6e238eec0335566088a9a8f2ab18482c693e3949213d97bd8873b9a0076fa174f70ad96c6db70ad0233198e1fa84c60fb3e4354e3065a
7
+ data.tar.gz: daa85190ef4bdc5f93f79c161e8443df77d02bfd095231cd3bc2bd5bf4ddfc347c4210b210bea2b2e29717ee088e1ecb825360fc55ec6bd299e9a893e62d33e0
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 2.2.3
2
+
3
+ * Introduce `Decorator::clone` to make sure cloning properly copies representable_attrs. in former versions, this would partially share definitions with subclasses when the decorator was an `inheritable_attr`.
4
+
1
5
  # 2.2.2
2
6
 
3
7
  * Bug fix: In 2.2.1 I accidentially removed a `super` call in `Representable::inherited` which leads to wrong behavior when having Representable mixed into a class along with other classes overriding `inherited`. Thanks to @jrmhaig for an [excellent bug report](https://github.com/apotonick/representable/issues/139#issuecomment-105926608) making it really easy to find the problem.
@@ -14,6 +14,12 @@ module Representable
14
14
  Representable::Decorator
15
15
  end
16
16
 
17
+ # This is called from inheritable_attr when inheriting a decorator class to a subclass.
18
+ # Explicitly subclassing the Decorator makes sure representable_attrs is a clean version.
19
+ def self.clone
20
+ Class.new(self) # DISCUSS: why isn't this called by Ruby?
21
+ end
22
+
17
23
  include Representable # include after class methods so Decorator::prepare can't be overwritten by Representable::prepare.
18
24
 
19
25
  # TODO: implement that just by calling ::property(name, options){include mod} on the inheriting representer.
@@ -51,11 +57,9 @@ module Representable
51
57
 
52
58
  private
53
59
  def self.build_inline(base, features, name, options, &block)
54
- Class.new(base || default_inline_class).tap do |decorator|
55
- decorator.class_eval do # Ruby 1.8.7 wouldn't properly execute the block passed to Class.new!
56
- feature *features
57
- class_eval &block
58
- end
60
+ Class.new(base || default_inline_class) do
61
+ feature *features
62
+ class_eval &block
59
63
  end
60
64
  end
61
65
  end
@@ -1,3 +1,3 @@
1
1
  module Representable
2
- VERSION = "2.2.2"
2
+ VERSION = "2.2.3"
3
3
  end
@@ -73,3 +73,25 @@ class DecoratorTest < MiniTest::Spec
73
73
  end
74
74
  end
75
75
  end
76
+
77
+ require "uber/inheritable_attr"
78
+ class InheritanceWithDecoratorTest < MiniTest::Spec
79
+ class Twin
80
+ extend Uber::InheritableAttr
81
+ inheritable_attr :representer_class
82
+ self.representer_class = Representable::Decorator
83
+ end
84
+
85
+ class Album < Twin
86
+ representer_class.property :title # Twin.representer_class.clone
87
+ end
88
+
89
+ class Song < Twin # Twin.representer_class.clone
90
+ end
91
+
92
+ it do
93
+ Twin.representer_class.representable_attrs[:definitions].size.must_equal 0
94
+ Album.representer_class.representable_attrs[:definitions].size.must_equal 1
95
+ Song.representer_class.representable_attrs[:definitions].size.must_equal 0
96
+ end
97
+ end
@@ -109,6 +109,56 @@ class RepresentableTest < MiniTest::Spec
109
109
  assert_xml_equal "<song name=\"Days Go By\"/>", @song.extend(SongXmlRepresenter).to_xml
110
110
  assert_json "{\"name\":\"Days Go By\"}", @song.extend(SongJsonRepresenter).to_json
111
111
  end
112
+
113
+
114
+ # test if we call super in
115
+ # ::inherited
116
+ # ::included
117
+ # ::extended
118
+ module Representer
119
+ include Representable # overrides ::inherited.
120
+ end
121
+
122
+ class BaseClass
123
+ def self.inherited(subclass)
124
+ super
125
+ subclass.instance_eval { def other; end }
126
+ end
127
+
128
+ include Representable # overrides ::inherited.
129
+ include Representer
130
+ end
131
+
132
+ class SubClass < BaseClass # triggers Representable::inherited, then OtherModule::inherited.
133
+ end
134
+
135
+ # test ::inherited.
136
+ it do
137
+ BaseClass.respond_to?(:other).must_equal false
138
+ SubClass.respond_to?(:other).must_equal true
139
+ end
140
+
141
+ module DifferentIncluded
142
+ def included(includer)
143
+ includer.instance_eval { def different; end }
144
+ end
145
+ end
146
+
147
+ module CombinedIncluded
148
+ extend DifferentIncluded # defines ::included.
149
+ include Representable # overrides ::included.
150
+ end
151
+
152
+ class IncludingClass
153
+ include Representable
154
+ include CombinedIncluded
155
+ end
156
+
157
+ # test ::included.
158
+ it do
159
+ IncludingClass.respond_to?(:representable_attrs) # from Representable
160
+ IncludingClass.respond_to?(:different)
161
+ end
112
162
  end
113
163
 
114
164
 
data/test/skip_test.rb CHANGED
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  class SkipParseTest < MiniTest::Spec
4
4
  representer! do
5
- property :title
5
+ property :title, skip_parse: lambda { |fragment, opts| opts[:skip?] and fragment == "skip me" }
6
6
  property :band,
7
7
  skip_parse: lambda { |fragment, opts| opts[:skip?] and fragment["name"].nil? }, class: OpenStruct do
8
8
  property :name
@@ -17,17 +17,32 @@ class SkipParseTest < MiniTest::Spec
17
17
  let (:song) { OpenStruct.new.extend(representer) }
18
18
 
19
19
  # do parse.
20
- it { song.from_hash({"band" => {"name" => "Mute 98"}}, skip?: true).band.name.must_equal "Mute 98" }
21
- it { song.from_hash({"airplays" => [{"station" => "JJJ"}]}, skip?: true).airplays[0].station.must_equal "JJJ" }
20
+ it do
21
+ song.from_hash({
22
+ "title" => "Victim Of Fate",
23
+ "band" => {"name" => "Mute 98"},
24
+ "airplays" => [{"station" => "JJJ"}]
25
+ }, skip?: true)
26
+
27
+ song.title.must_equal "Victim Of Fate"
28
+ song.band.name.must_equal "Mute 98"
29
+ song.airplays[0].station.must_equal "JJJ"
30
+ end
22
31
 
23
32
  # skip parsing.
24
- it { song.from_hash({"band" => {}}, skip?: true).band.must_equal nil }
25
- # skip_parse is _per item_.
26
33
  let (:airplay) { OpenStruct.new(station: "JJJ") }
27
- it { song.from_hash({"airplays" => [{"station" => "JJJ"}, {}]}, skip?: true).airplays.must_equal [airplay] }
28
34
 
29
- # it skips parsing of items as if they hadn't been in the document.
30
- it { song.from_hash({"airplays" => [{"station" => "JJJ"}, {}, {"station" => "JJJ"}]}, skip?: true).airplays.must_equal [airplay, airplay] }
35
+ it do
36
+ song.from_hash({
37
+ "title" => "skip me",
38
+ "band" => {},
39
+ "airplays" => [{"station" => "JJJ"}, {}],
40
+ }, skip?: true)
41
+
42
+ song.title.must_equal nil
43
+ song.band.must_equal nil
44
+ song.airplays.must_equal [airplay]
45
+ end
31
46
  end
32
47
 
33
48
  class SkipRenderTest < MiniTest::Spec
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.2.2
4
+ version: 2.2.3
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-05-27 00:00:00.000000000 Z
11
+ date: 2015-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -279,53 +279,4 @@ signing_key:
279
279
  specification_version: 4
280
280
  summary: Renders and parses JSON/XML/YAML documents from and to Ruby objects. Includes
281
281
  plain properties, collections, nesting, coercion and more.
282
- test_files:
283
- - test/as_test.rb
284
- - test/benchmarking.rb
285
- - test/binding_test.rb
286
- - test/cached_test.rb
287
- - test/class_test.rb
288
- - test/coercion_test.rb
289
- - test/config/inherit_test.rb
290
- - test/config_test.rb
291
- - test/decorator_scope_test.rb
292
- - test/decorator_test.rb
293
- - test/definition_test.rb
294
- - test/example.rb
295
- - test/examples/object.rb
296
- - test/exec_context_test.rb
297
- - test/features_test.rb
298
- - test/filter_test.rb
299
- - test/for_collection_test.rb
300
- - test/generic_test.rb
301
- - test/getter_setter_test.rb
302
- - test/hash_bindings_test.rb
303
- - test/hash_test.rb
304
- - test/if_test.rb
305
- - test/inherit_test.rb
306
- - test/inheritable_test.rb
307
- - test/inline_test.rb
308
- - test/instance_test.rb
309
- - test/is_representable_test.rb
310
- - test/json_test.rb
311
- - test/lonely_test.rb
312
- - test/mongoid_test.rb
313
- - test/nested_test.rb
314
- - test/object_test.rb
315
- - test/parse_strategy_test.rb
316
- - test/pass_options_test.rb
317
- - test/prepare_test.rb
318
- - test/reader_writer_test.rb
319
- - test/realistic_benchmark.rb
320
- - test/represent_test.rb
321
- - test/representable_test.rb
322
- - test/schema_test.rb
323
- - test/serialize_deserialize_test.rb
324
- - test/skip_test.rb
325
- - test/stringify_hash_test.rb
326
- - test/test_helper.rb
327
- - test/test_helper_test.rb
328
- - test/wrap_test.rb
329
- - test/xml_bindings_test.rb
330
- - test/xml_test.rb
331
- - test/yaml_test.rb
282
+ test_files: []