resource_manager 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/resource_manager/version.rb +1 -1
- data/lib/resource_manager.rb +4 -4
- data/spec/lib/resource_manager_spec.rb +19 -7
- 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: ff1ede6e2576d28ac901de727a9822b69b763087
|
4
|
+
data.tar.gz: 568c1a0621b8af33bbcba4dc97531449c8ce487c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5de03bf7c82f827672d667e066f734d7c1ed998c995bc2cb40457f202d1c8632e6c4be85b8e114cbf4dd5dcb5698a3aa4efcb5e4f231b36090f1febf0dcecdb5
|
7
|
+
data.tar.gz: 09258a64969fbad4b282dbbe04226e698ead60933e6c0deb0ba8cd4eb6265672e2416b0b9380b44be0d7f83d754b1cfd5487e9da72d9f379bff3ab57c2a981e4
|
data/lib/resource_manager.rb
CHANGED
@@ -34,7 +34,7 @@ module ResourceManager
|
|
34
34
|
end
|
35
35
|
|
36
36
|
['', '!'].each do |name|
|
37
|
-
define_method "create#{name}" do |params|
|
37
|
+
define_method "create#{name}" do |params, &block|
|
38
38
|
transaction do
|
39
39
|
run_callback(:before_create, params)
|
40
40
|
|
@@ -43,7 +43,7 @@ module ResourceManager
|
|
43
43
|
else
|
44
44
|
item = model.new(params)
|
45
45
|
saved = item.send("save#{name}")
|
46
|
-
|
46
|
+
block.call(item, saved) if block.present?
|
47
47
|
item
|
48
48
|
end
|
49
49
|
|
@@ -52,7 +52,7 @@ module ResourceManager
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
define_method "update#{name}" do |item_or_id, params|
|
55
|
+
define_method "update#{name}" do |item_or_id, params, &block|
|
56
56
|
transaction do
|
57
57
|
item = item(item_or_id)
|
58
58
|
run_callback(:before_update, item, params)
|
@@ -63,7 +63,7 @@ module ResourceManager
|
|
63
63
|
item.assign_attributes(params)
|
64
64
|
changed = item.changed
|
65
65
|
saved = item.send("save#{name}")
|
66
|
-
|
66
|
+
block.call(item, saved) if block.present?
|
67
67
|
item
|
68
68
|
end
|
69
69
|
|
@@ -61,12 +61,18 @@ describe ResourceManager::Base do
|
|
61
61
|
expect(result_item).to be_nil
|
62
62
|
end
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'yields block' do
|
68
|
+
_item = nil
|
69
|
+
_result = nil
|
70
|
+
manager.create({test: 1}) do |item, result|
|
71
|
+
_item = item
|
72
|
+
_result = result
|
69
73
|
end
|
74
|
+
expect(_item).to be_a_kind_of(Model)
|
75
|
+
expect(_result).to be_truthy
|
70
76
|
end
|
71
77
|
end
|
72
78
|
|
@@ -120,10 +126,16 @@ describe ResourceManager::Base do
|
|
120
126
|
end
|
121
127
|
|
122
128
|
it 'yields block' do
|
129
|
+
_item = nil
|
130
|
+
_result = nil
|
131
|
+
|
123
132
|
manager.update(1, {test: 1}) do |item, result|
|
124
|
-
|
125
|
-
|
133
|
+
_item = item
|
134
|
+
_result = result
|
126
135
|
end
|
136
|
+
|
137
|
+
expect(_item).to be_a_kind_of(Model)
|
138
|
+
expect(_result).to be_truthy
|
127
139
|
end
|
128
140
|
|
129
141
|
context 'with failed saving' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resource_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gleb Sinyavsky
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|