o_patch 0.0.2 → 0.1.0

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: 2acac7437a2fda4c9d014ce2aea3f2c6ee7fd927
4
- data.tar.gz: 33f410f04aae3cc1ad121c814309d13b380fde43
3
+ metadata.gz: 0fbde46f8ffb9e7aa4c03f748d77fe6d237210f6
4
+ data.tar.gz: ee73b03b55087b5e5ec762346b1868f4f4069aac
5
5
  SHA512:
6
- metadata.gz: 89e83a940dcad0c3b670ba7b7d80033ab3a0495d8d871c282d6669bf46c4719db26031961e6d8548265ad2c557085998d1014147981040253ba776268fba38d2
7
- data.tar.gz: 1856749f67be4da20d40aa9e3f014964d46c20faed70273e053bf59fd36dfda7c2eee54f4f52a2a4a8b6073471e383183109727d5157fb038e06facca597c030
6
+ metadata.gz: c71c3764ad7d73dfa17fe3f33f99424d301d1293902a4759e97c8f6bcfcc35d09890fe76bb8405a5ea90b639ef70f8d82dca1d80637f33ad4bbbee7cdea6c12d
7
+ data.tar.gz: 13053423853b8253a31eaf6283ea4da5e79cd0d84fa9db3f755922505c71c0819804cd9d9f40e8dae521fe90749829a6e9224f13a86800d831889c02f5634b18
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- o_patch (0.0.2)
4
+ o_patch (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -29,7 +29,12 @@ class OPatch::Patcher
29
29
  def object(field_name, options = {}, &block)
30
30
  if attributes.has_key?(field_name)
31
31
  if attributes[field_name].nil?
32
- entity.send("#{field_name}=", nil)
32
+ remove_block = options[:remove]
33
+ if remove_block
34
+ remove_block.call(entity)
35
+ else
36
+ entity.send("#{field_name}=", nil)
37
+ end
33
38
  else
34
39
  child_entity = entity.send(field_name)
35
40
  if child_entity
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "o_patch"
6
- spec.version = "0.0.2"
6
+ spec.version = "0.1.0"
7
7
  spec.authors = ["Albert Gazizov"]
8
8
  spec.description = %q{Declarative ruby objects patcher}
9
9
  spec.summary = %q{Declarative ruby objects patcher}
@@ -97,6 +97,18 @@ describe OPatch do
97
97
  end
98
98
  end.to raise_error(ArgumentError, "address build block should be specified")
99
99
  end
100
+
101
+ it "should remove nested object if nil was given" do
102
+ person = Person.new('Ivan')
103
+ person.build_address(counry: 'Russia', city: 'Kazan')
104
+
105
+ OPatch.patch(person, name: 'Vasya', address: nil) do
106
+ field :name
107
+ object :address, remove: proc { |person, attributes| person.address = :removed }
108
+ end
109
+
110
+ person.address.should == :removed
111
+ end
100
112
  end
101
113
 
102
114
  context "nested collection" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: o_patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Albert Gazizov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-19 00:00:00.000000000 Z
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler