representable 2.1.4 → 2.1.5

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: 19f89d36352fe54ab21a3759d6c85392950dc564
4
- data.tar.gz: c3e581d0e9fb29d0a47f608a8b9b960b48f83fe4
3
+ metadata.gz: 351c7071b33faa1215070024868b2614288915f4
4
+ data.tar.gz: 9960a2f4c850764bc48ad3db09c84581fb53049a
5
5
  SHA512:
6
- metadata.gz: a4cdc220373cb17d0f9934ddc8224925938c274a9489f8da931bcdac9c9782ecde3f1b5204bf7b9b7643b28105b52ba80b786e150d480a8893549e264f3612ce
7
- data.tar.gz: 545f594e8786f27d2fca07dcd41241b9b754aacc9298fc02f24f8ff8916381046e24d03bb6907062a323448bc85c4403713e43aa04aaf2bd0f8032cfe519dd74
6
+ metadata.gz: ae7afd058a763a369761633d3375d865d583e7761988665580c6765980b254dc0443cdc3c3b641a5de3f94476f2cecaa23550dc3bc72c0f10e9b2d215fb6c269
7
+ data.tar.gz: f44ba7ec3298e2d264be42f491561a00dbb1375a3ff347848abdb4ab5a87d603ad86a1f513721752b48864204be89e2fd5ce512b068d5fc0c183c7c1b0aef106
data/CHANGES.md CHANGED
@@ -1,3 +1,13 @@
1
+ # 2.1.5
2
+
3
+ * Using `inherit: true` now works even if the parent property hasn't been defined before. It will simply create a new property. This used to crash with `undefined method `merge!' for nil:NilClass`.
4
+
5
+ ```ruby
6
+ class SongRepresenter < Representable::Decorator
7
+ property :title, inherit: true # this will create a brand-new :title property.
8
+ end
9
+ ```
10
+
1
11
  # 2.1.4
2
12
 
3
13
  * Allow lonely collection representers without configuration, with inline representer, only. This is for render-only collection representers and very handy.
@@ -28,9 +28,10 @@ module Representable
28
28
  end
29
29
 
30
30
  def add(name, options, &block)
31
- if options[:inherit] # i like that: the :inherit shouldn't be handled outside.
32
- return get(name).merge!(options, &block)
31
+ if options[:inherit] and parent_property = get(name) # i like that: the :inherit shouldn't be handled outside.
32
+ return parent_property.merge!(options, &block)
33
33
  end
34
+ options.delete(:inherit) # TODO: can we handle the :inherit in one single place?
34
35
 
35
36
  self[name.to_s] = definition_class.new(name, options, &block)
36
37
  end
@@ -1,3 +1,3 @@
1
1
  module Representable
2
- VERSION = "2.1.4"
2
+ VERSION = "2.1.5"
3
3
  end
@@ -115,6 +115,16 @@ class InheritTest < MiniTest::Spec
115
115
  it { inheriting.new(OpenStruct.new(:hit => OpenStruct.new(:title => "Hole In Your Soul", :length => "2:59"))).to_hash.must_equal(
116
116
  {"hit"=>{"title"=>"Hole In Your Soul", "length"=>"2:59"}}) }
117
117
  end
118
+
119
+
120
+ # :inherit when property doesn't exist, yet.
121
+ describe ":inherit without inheritable property" do
122
+ representer! do
123
+ property :name, :inherit => true
124
+ end
125
+
126
+ it { representer.prepare(Song.new("The Beginning")).to_hash.must_equal({"name"=>"The Beginning"})}
127
+ end
118
128
  end
119
129
 
120
130
 
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.1.4
4
+ version: 2.1.5
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-01-21 00:00:00.000000000 Z
11
+ date: 2015-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri