Class: ReportLogic::Base
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Decorable
#decorators
Constructor Details
#initialize(collection = nil) ⇒ Base
Returns a new instance of Base.
7
8
9
|
# File 'lib/report_logic/base.rb', line 7
def initialize(collection = nil)
@collection = collection
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/report_logic/base.rb', line 28
def method_missing(method_name, *args, &block)
if @current_session && @current_session.public_methods.include?(method_name)
@current_session.public_send(method_name, *args, &block)
else
super
end
end
|
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
5
6
7
|
# File 'lib/report_logic/base.rb', line 5
def collection
@collection
end
|
Instance Method Details
#count ⇒ Object
24
25
26
|
# File 'lib/report_logic/base.rb', line 24
def count
@collection.size
end
|
#decorate_with(*args) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/report_logic/base.rb', line 36
def decorate_with(*args)
if @current_session
@current_session.decorate_with(*args)
else
super
end
end
|
#each(key) ⇒ Object
11
12
13
14
15
|
# File 'lib/report_logic/base.rb', line 11
def each(key)
return to_enum(__callee__, key) unless block_given?
ensure_built_and_decorated
sessions[key] and sessions[key].fields.each { |field| yield field }
end
|
#session(key, collection = nil, &block) ⇒ Object
17
18
19
20
21
22
|
# File 'lib/report_logic/base.rb', line 17
def session(key, collection = nil, &block)
@current_session = sessions[key] ||= Session.new(key, self)
@current_session.process(collection, &block)
ensure
@current_session = nil
end
|