Class: Compendium::Report
- Inherits:
-
Object
- Object
- Compendium::Report
- Extended by:
- DSL
- Defined in:
- lib/compendium/report.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
-
#results ⇒ Object
Returns the value of attribute results.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Report
constructor
A new instance of Report.
- #metrics ⇒ Object
- #run(context = nil) ⇒ Object
Methods included from DSL
extended, metric, option, query
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
39 40 41 42 43 44 45 46 47 |
# File 'lib/compendium/report.rb', line 39 def method_missing(name, *args, &block) prefix = name.to_s.sub(/(?:_results|\?)\Z/, '').to_sym return queries[name] if queries.keys.include?(name) return results[prefix] if name.to_s.end_with? '_results' and queries.keys.include?(prefix) return params[name] if .keys.include?(name) return !!params[prefix] if name.to_s.end_with? '?' and .keys.include?(prefix) super end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
7 8 9 |
# File 'lib/compendium/report.rb', line 7 def params @params end |
#results ⇒ Object
Returns the value of attribute results.
7 8 9 |
# File 'lib/compendium/report.rb', line 7 def results @results end |
Class Method Details
.inherited(report) ⇒ Object
11 12 13 |
# File 'lib/compendium/report.rb', line 11 def self.inherited(report) Compendium.reports << report end |
Instance Method Details
#metrics ⇒ Object
31 32 33 |
# File 'lib/compendium/report.rb', line 31 def metrics Collection[Metric, queries.map{ |q| q.metrics.to_a }.flatten] end |
#run(context = nil) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/compendium/report.rb', line 22 def run(context = nil) self.context = context self.results = {} queries.each{ |q| self.results[q.name] = q.run(params, ContextWrapper.wrap(context, self)) } self end |