representable 1.4.1 → 1.4.2
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.
- data/CHANGES.textile +4 -0
- data/README.md +2 -0
- data/lib/representable/binding.rb +1 -1
- data/lib/representable/version.rb +1 -1
- data/representable.gemspec +1 -1
- data/test/representable_test.rb +14 -5
- metadata +3 -3
data/CHANGES.textile
CHANGED
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
|
data/representable.gemspec
CHANGED
@@ -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 = "
|
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
|
|
data/test/representable_test.rb
CHANGED
@@ -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]} #{
|
504
|
-
:setter => lambda { |val, args| self.
|
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(:
|
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").
|
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.
|
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-
|
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:
|
209
|
+
homepage: https://github.com/apotonick/representable/
|
210
210
|
licenses: []
|
211
211
|
post_install_message:
|
212
212
|
rdoc_options: []
|