o_patch 0.0.2 → 0.1.0
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/o_patch/patcher.rb +6 -1
- data/o_patch.gemspec +1 -1
- data/spec/o_patch/o_patch_spec.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fbde46f8ffb9e7aa4c03f748d77fe6d237210f6
|
4
|
+
data.tar.gz: ee73b03b55087b5e5ec762346b1868f4f4069aac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c71c3764ad7d73dfa17fe3f33f99424d301d1293902a4759e97c8f6bcfcc35d09890fe76bb8405a5ea90b639ef70f8d82dca1d80637f33ad4bbbee7cdea6c12d
|
7
|
+
data.tar.gz: 13053423853b8253a31eaf6283ea4da5e79cd0d84fa9db3f755922505c71c0819804cd9d9f40e8dae521fe90749829a6e9224f13a86800d831889c02f5634b18
|
data/Gemfile.lock
CHANGED
data/lib/o_patch/patcher.rb
CHANGED
@@ -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
|
-
|
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
|
data/o_patch.gemspec
CHANGED
@@ -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
|
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
|
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-
|
11
|
+
date: 2015-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|