Class: Rack::Client::BodyCollection
- Inherits:
-
Object
- Object
- Rack::Client::BodyCollection
show all
- Defined in:
- lib/rack/client/parser/body_collection.rb
Instance Method Summary
collapse
Constructor Details
#initialize(&load_with_proc) ⇒ BodyCollection
Returns a new instance of BodyCollection.
6
7
8
9
10
11
12
13
14
|
# File 'lib/rack/client/parser/body_collection.rb', line 6
def initialize(&load_with_proc)
raise ArgumentException, 'BodyCollection must be initialized with a block' unless block_given?
@loaded = false
@finished = false
@load_with_proc = load_with_proc
@callbacks = []
@array = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *a, &b) ⇒ Object
44
45
46
47
|
# File 'lib/rack/client/parser/body_collection.rb', line 44
def method_missing(sym, *a, &b)
lazy_load
@array.send(sym, *a, &b)
end
|
Instance Method Details
#<<(value) ⇒ Object
31
32
33
34
|
# File 'lib/rack/client/parser/body_collection.rb', line 31
def <<(value)
@array << value
@callbacks.each {|cb| cb[value] }
end
|
#each(&block) ⇒ Object
16
17
18
19
20
21
22
23
|
# File 'lib/rack/client/parser/body_collection.rb', line 16
def each(&block)
@callbacks << block
@array.each {|a| yield(*a) }
lazy_load unless finished?
ensure
@callbacks.delete(block)
end
|
#finish ⇒ Object
40
41
42
|
# File 'lib/rack/client/parser/body_collection.rb', line 40
def finish
@finished = true
end
|
#finished? ⇒ Boolean
36
37
38
|
# File 'lib/rack/client/parser/body_collection.rb', line 36
def finished?
@finished
end
|
#lazy_load ⇒ Object
25
26
27
28
29
|
# File 'lib/rack/client/parser/body_collection.rb', line 25
def lazy_load
until finished?
@load_with_proc[self]
end
end
|