nested 0.0.12 → 0.0.13
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/lib/nested.rb +20 -29
- data/nested.gemspec +1 -1
- data/test/nested_test.rb +17 -17
- 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: 55bc0e32ebd2026fff78d9f51d3442b566644d8c
|
4
|
+
data.tar.gz: 258a00be59fff86245c67a1a229de723e94b28e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6059be129db9adc1bd3d1b97590427029c19e15852570875cfa460577fd9421ece0ab5ece5c57edff733f3e11af10d96661278383eddeabf03b716003b772df
|
7
|
+
data.tar.gz: f70c325da379d55242d92ca7cd06f3bf9f2abfc3c86fe87514b01b4d125e5e1edce99e5e1e27b0c2843eb10e0a2d7b0952c830f1389f179aeddb2f2bd4314bee
|
data/lib/nested.rb
CHANGED
@@ -32,7 +32,7 @@ module Nested
|
|
32
32
|
|
33
33
|
attr_reader :name, :parent, :actions, :resources
|
34
34
|
|
35
|
-
def initialize(sinatra, name, singleton, collection, parent)
|
35
|
+
def initialize(sinatra, name, singleton, collection, parent, init_block)
|
36
36
|
raise SingletonAndCollectionError.new if singleton && collection
|
37
37
|
raise NameMissingError.new if (singleton || collection) && !name
|
38
38
|
|
@@ -45,7 +45,7 @@ module Nested
|
|
45
45
|
@actions = []
|
46
46
|
|
47
47
|
init &-> do
|
48
|
-
fetched = instance_exec(&FETCH)
|
48
|
+
fetched = instance_exec(&(init_block||FETCH))
|
49
49
|
|
50
50
|
puts "set @#{@__resource.instance_variable_name} to #{fetched.inspect} for #{self}"
|
51
51
|
self.instance_variable_set("@#{@__resource.instance_variable_name}", fetched)
|
@@ -133,32 +133,22 @@ module Nested
|
|
133
133
|
create_sinatra_route :delete, action, &block
|
134
134
|
end
|
135
135
|
|
136
|
-
def singleton(name, &block)
|
137
|
-
child_resource(name, true, false, &block)
|
136
|
+
def singleton(name, init_block=nil, &block)
|
137
|
+
child_resource(name, true, false, init_block, &block)
|
138
138
|
end
|
139
139
|
|
140
|
-
def
|
141
|
-
singleton(name) do
|
142
|
-
resource = self
|
143
|
-
init do
|
144
|
-
instance_variable_set("@#{resource.instance_variable_name}", instance_variable_get("@#{resource.parent.instance_variable_name}"))
|
145
|
-
end
|
146
|
-
instance_eval(&block)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
def many(name, &block)
|
140
|
+
def many(name, init_block=nil, &block)
|
151
141
|
raise ManyInManyError.new "do not nest many in many" if collection?
|
152
|
-
child_resource(name, false, true, &block)
|
142
|
+
child_resource(name, false, true, init_block, &block)
|
153
143
|
end
|
154
144
|
|
155
|
-
def one(name=nil, &block)
|
145
|
+
def one(name=nil, init_block=nil, &block)
|
156
146
|
raise OneWithNameInManyError.new("call one (#{name}) without name argument when nested in a many (#{@name})") if name && collection?
|
157
|
-
child_resource(name, false, false, &block)
|
147
|
+
child_resource(name, false, false, init_block, &block)
|
158
148
|
end
|
159
149
|
|
160
|
-
def child_resource(name, singleton, collection, &block)
|
161
|
-
Resource.new(@sinatra, name, singleton, collection, self)
|
150
|
+
def child_resource(name, singleton, collection, init_block, &block)
|
151
|
+
Resource.new(@sinatra, name, singleton, collection, self, init_block)
|
162
152
|
.tap{|r| r.instance_eval(&block)}
|
163
153
|
.tap{|r| @resources << r}
|
164
154
|
end
|
@@ -278,7 +268,8 @@ module Nested
|
|
278
268
|
end
|
279
269
|
|
280
270
|
module Sinatra
|
281
|
-
def create_resource(name, singleton, collection, &block)
|
271
|
+
# def create_resource(name, singleton, collection, &block)
|
272
|
+
def create_resource(*args, &block)
|
282
273
|
angularize(super)
|
283
274
|
end
|
284
275
|
|
@@ -430,17 +421,17 @@ module Nested
|
|
430
421
|
@nested_config ||= {}
|
431
422
|
end
|
432
423
|
end
|
433
|
-
def singleton(name, &block)
|
434
|
-
create_resource(name, true, false, &block)
|
424
|
+
def singleton(name, init_block=nil, &block)
|
425
|
+
create_resource(name, true, false, init_block, &block)
|
435
426
|
end
|
436
|
-
def many(name, &block)
|
437
|
-
create_resource(name, false, true, &block)
|
427
|
+
def many(name, init_block=nil, &block)
|
428
|
+
create_resource(name, false, true, init_block, &block)
|
438
429
|
end
|
439
|
-
def one(name, &block)
|
440
|
-
create_resource(name, false, false, &block)
|
430
|
+
def one(name, init_block=nil, &block)
|
431
|
+
create_resource(name, false, false, init_block, &block)
|
441
432
|
end
|
442
|
-
def create_resource(name, singleton, collection, &block)
|
443
|
-
::Nested::Resource.new(self, name, singleton, collection, nil).tap{|r| r.instance_eval(&block) }
|
433
|
+
def create_resource(name, singleton, collection, init_block, &block)
|
434
|
+
::Nested::Resource.new(self, name, singleton, collection, nil, init_block).tap{|r| r.instance_eval(&block) }
|
444
435
|
end
|
445
436
|
end
|
446
437
|
|
data/nested.gemspec
CHANGED
data/test/nested_test.rb
CHANGED
@@ -8,15 +8,15 @@ require "nested"
|
|
8
8
|
class NestedTest < Test::Unit::TestCase
|
9
9
|
|
10
10
|
def singleton!
|
11
|
-
@r = Nested::Resource.new(@sinatra, :project, true, false, nil)
|
11
|
+
@r = Nested::Resource.new(@sinatra, :project, true, false, nil, nil)
|
12
12
|
end
|
13
13
|
|
14
14
|
def collection!
|
15
|
-
@r = Nested::Resource.new(@sinatra, :project, false, true, nil)
|
15
|
+
@r = Nested::Resource.new(@sinatra, :project, false, true, nil, nil)
|
16
16
|
end
|
17
17
|
|
18
18
|
def member!
|
19
|
-
@r = Nested::Resource.new(@sinatra, :project, false, false, nil)
|
19
|
+
@r = Nested::Resource.new(@sinatra, :project, false, false, nil, nil)
|
20
20
|
end
|
21
21
|
|
22
22
|
def setup
|
@@ -25,11 +25,11 @@ class NestedTest < Test::Unit::TestCase
|
|
25
25
|
|
26
26
|
def test_initialize_name
|
27
27
|
assert_raise Nested::NameMissingError do
|
28
|
-
Nested::Resource.new({}, nil, true, false, nil)
|
28
|
+
Nested::Resource.new({}, nil, true, false, nil, nil)
|
29
29
|
end
|
30
30
|
|
31
31
|
assert_raise Nested::NameMissingError do
|
32
|
-
Nested::Resource.new({}, nil, false, true, nil)
|
32
|
+
Nested::Resource.new({}, nil, false, true, nil, nil)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -140,29 +140,29 @@ class NestedTest < Test::Unit::TestCase
|
|
140
140
|
|
141
141
|
def test_singleton
|
142
142
|
singleton!
|
143
|
-
@r.expects(:child_resource).with(:statistic, true, false)
|
143
|
+
@r.expects(:child_resource).with(:statistic, true, false, nil)
|
144
144
|
@r.singleton(:statistic)
|
145
145
|
|
146
146
|
member!
|
147
|
-
@r.expects(:child_resource).with(:statistic, true, false)
|
147
|
+
@r.expects(:child_resource).with(:statistic, true, false, nil)
|
148
148
|
@r.singleton(:statistic)
|
149
149
|
|
150
150
|
collection!
|
151
|
-
@r.expects(:child_resource).with(:statistic, true, false)
|
151
|
+
@r.expects(:child_resource).with(:statistic, true, false, nil)
|
152
152
|
@r.singleton(:statistic)
|
153
153
|
end
|
154
154
|
|
155
155
|
def test_one
|
156
156
|
singleton!
|
157
|
-
@r.expects(:child_resource).with(:statistic, false, false)
|
157
|
+
@r.expects(:child_resource).with(:statistic, false, false, nil)
|
158
158
|
@r.one(:statistic)
|
159
159
|
|
160
160
|
member!
|
161
|
-
@r.expects(:child_resource).with(:statistic, false, false)
|
161
|
+
@r.expects(:child_resource).with(:statistic, false, false, nil)
|
162
162
|
@r.one(:statistic)
|
163
163
|
|
164
164
|
collection!
|
165
|
-
@r.expects(:child_resource).with(nil, false, false)
|
165
|
+
@r.expects(:child_resource).with(nil, false, false, nil)
|
166
166
|
@r.one
|
167
167
|
|
168
168
|
collection!
|
@@ -173,11 +173,11 @@ class NestedTest < Test::Unit::TestCase
|
|
173
173
|
|
174
174
|
def test_many
|
175
175
|
singleton!
|
176
|
-
@r.expects(:child_resource).with(:statistics, false, true)
|
176
|
+
@r.expects(:child_resource).with(:statistics, false, true, nil)
|
177
177
|
@r.many(:statistics)
|
178
178
|
|
179
179
|
member!
|
180
|
-
@r.expects(:child_resource).with(:statistics, false, true)
|
180
|
+
@r.expects(:child_resource).with(:statistics, false, true, nil)
|
181
181
|
@r.many(:statistics)
|
182
182
|
|
183
183
|
collection!
|
@@ -228,26 +228,26 @@ class NestedTest < Test::Unit::TestCase
|
|
228
228
|
|
229
229
|
def test_child_resource
|
230
230
|
singleton!
|
231
|
-
r = @r.child_resource(:statistic, false, false) { }
|
231
|
+
r = @r.child_resource(:statistic, false, false, nil) { }
|
232
232
|
assert_equal :statistic, r.name
|
233
233
|
assert_equal false, r.instance_variable_get("@singleton")
|
234
234
|
assert_equal false, r.instance_variable_get("@collection")
|
235
235
|
|
236
236
|
singleton!
|
237
|
-
r = @r.child_resource(:statistic, true, false) { }
|
237
|
+
r = @r.child_resource(:statistic, true, false, nil) { }
|
238
238
|
assert_equal :statistic, r.name
|
239
239
|
assert_equal true, r.instance_variable_get("@singleton")
|
240
240
|
assert_equal false, r.instance_variable_get("@collection")
|
241
241
|
|
242
242
|
singleton!
|
243
|
-
r = @r.child_resource(:statistic, false, true) { }
|
243
|
+
r = @r.child_resource(:statistic, false, true, nil) { }
|
244
244
|
assert_equal :statistic, r.name
|
245
245
|
assert_equal false, r.instance_variable_get("@singleton")
|
246
246
|
assert_equal true, r.instance_variable_get("@collection")
|
247
247
|
|
248
248
|
singleton!
|
249
249
|
assert_raise Nested::SingletonAndCollectionError do
|
250
|
-
@r.child_resource(:statistic, true, true) { }
|
250
|
+
@r.child_resource(:statistic, true, true, nil) { }
|
251
251
|
end
|
252
252
|
end
|
253
253
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nested
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Zimmek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|