representable 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ h2. 1.4.2
2
+
3
+ * Fix the processing of `:setter`, we called both the setter lambda and the setter method.
4
+
1
5
  h2. 1.4.1
2
6
 
3
7
  * Added `:representer_exec` to have lambdas be executed in decorator instance context.
data/README.md CHANGED
@@ -560,10 +560,12 @@ Use the `:type` option to specify the conversion target. Note that `:default` st
560
560
 
561
561
  * If you need a special binding for a property you're free to create it using the `:binding` option.
562
562
 
563
+ <!-- here comes some code -->
563
564
  property :title, :binding => lambda { |*args| JSON::TitleBinding.new(*args) }
564
565
 
565
566
  * Lambdas are usually executed in the represented object's context. If your writing a `Decorator` representer and you need to execute lambdas in its context use the `:representer_exec` option.
566
567
 
568
+ <!-- and some more in a beautiful cuddle -->
567
569
  class SongRepresenter < Representable::Decorator
568
570
  property :title, :representer_exec => true, :getter => lambda {..}
569
571
  end
@@ -82,7 +82,7 @@ module Representable
82
82
  end
83
83
 
84
84
  def set(value)
85
- value = represented_exec_for(:setter, value) if options[:setter]
85
+ return represented_exec_for(:setter, value) if options[:setter]
86
86
  represented.send(setter, value)
87
87
  end
88
88
 
@@ -1,3 +1,3 @@
1
1
  module Representable
2
- VERSION = "1.4.1"
2
+ VERSION = "1.4.2"
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.authors = ["Nick Sutterer"]
12
12
  s.email = ["apotonick@gmail.com"]
13
- s.homepage = "http://representable.apotomo.de"
13
+ s.homepage = "https://github.com/apotonick/representable/"
14
14
  s.summary = %q{Maps representation documents from and to Ruby objects. Includes XML and JSON support, plain properties, collections and compositions.}
15
15
  s.description = %q{Maps representation documents from and to Ruby objects. Includes XML and JSON support, plain properties, collections and compositions.}
16
16
 
@@ -499,19 +499,28 @@ class RepresentableTest < MiniTest::Spec
499
499
 
500
500
  describe ":getter and :setter" do
501
501
  representer! do
502
- property :name,
503
- :getter => lambda { |args| "#{args[:welcome]} #{name}" },
504
- :setter => lambda { |val, args| self.name = "#{args[:welcome]} #{val}" }
502
+ property :name, # key under :name.
503
+ :getter => lambda { |args| "#{args[:welcome]} #{song_name}" },
504
+ :setter => lambda { |val, args| self.song_name = "#{args[:welcome]} #{val}" }
505
505
  end
506
506
 
507
- subject { OpenStruct.new(:name => "Mony Mony").extend(representer) }
507
+ subject { OpenStruct.new(:song_name => "Mony Mony").extend(representer) }
508
508
 
509
509
  it "uses :getter when rendering" do
510
+ subject.instance_eval { def name; raise; end }
510
511
  subject.to_hash(:welcome => "Hi").must_equal({"name" => "Hi Mony Mony"})
511
512
  end
512
513
 
514
+ it "does not call original reader when rendering" do
515
+ subject.instance_eval { def name; raise; end; self }.to_hash
516
+ end
517
+
513
518
  it "uses :setter when parsing" do
514
- subject.from_hash({"name" => "Eyes Without A Face"}, :welcome => "Hello").name.must_equal "Hello Eyes Without A Face"
519
+ subject.from_hash({"name" => "Eyes Without A Face"}, :welcome => "Hello").song_name.must_equal "Hello Eyes Without A Face"
520
+ end
521
+
522
+ it "does not call original writer when parsing" do
523
+ subject.instance_eval { def name=(*); raise; end; self }.from_hash({"name"=>"Dana D And Talle T"})
515
524
  end
516
525
  end
517
526
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: representable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-26 00:00:00.000000000 Z
12
+ date: 2013-05-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -206,7 +206,7 @@ files:
206
206
  - test/xml_bindings_test.rb
207
207
  - test/xml_test.rb
208
208
  - test/yaml_test.rb
209
- homepage: http://representable.apotomo.de
209
+ homepage: https://github.com/apotonick/representable/
210
210
  licenses: []
211
211
  post_install_message:
212
212
  rdoc_options: []