Class: QueryReport::Report
- Inherits:
-
Object
- Object
- QueryReport::Report
- Includes:
- ColumnModule, FilterModule
- Defined in:
- lib/query_report/report.rb
Instance Attribute Summary collapse
-
#chart ⇒ Object
Returns the value of attribute chart.
-
#charts ⇒ Object
Returns the value of attribute charts.
-
#current_scope ⇒ Object
Returns the value of attribute current_scope.
-
#filters ⇒ Object
Returns the value of attribute filters.
-
#options ⇒ Object
Returns the value of attribute options.
-
#params ⇒ Object
Returns the value of attribute params.
-
#scopes ⇒ Object
Returns the value of attribute scopes.
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
- #all_records ⇒ Object
- #compare_with_column_chart(title, x_axis = '', &block) ⇒ Object
-
#initialize(params, template, options = {}, &block) ⇒ Report
constructor
A new instance of Report.
- #map_record(query) ⇒ Object
-
#method_missing(meth, *args, &block) ⇒ Object
to support the helper methods.
- #model_name ⇒ Object
- #pie_chart(title, &block) ⇒ Object
- #query ⇒ Object
- #query=(query) ⇒ Object
- #query_without_pagination ⇒ Object
- #records ⇒ Object
- #scope(scope) ⇒ Object
- #search ⇒ Object
Methods included from FilterModule
Methods included from ColumnModule
#column, #column_names, #columns
Constructor Details
#initialize(params, template, options = {}, &block) ⇒ Report
Returns a new instance of Report.
15 16 17 18 19 20 21 |
# File 'lib/query_report/report.rb', line 15 def initialize(params, template, ={}, &block) @params, @template = params, template @columns, @filters, @scopes, @charts = [], [], [], [] @current_scope = @params[:scope] || 'all' = QueryReport::DEFAULT_OPTIONS.merge instance_eval &block if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
to support the helper methods
32 33 34 35 36 37 38 |
# File 'lib/query_report/report.rb', line 32 def method_missing(meth, *args, &block) if @template.respond_to?(meth) @template.send(meth, *args) else super end end |
Instance Attribute Details
#chart ⇒ Object
Returns the value of attribute chart.
13 14 15 |
# File 'lib/query_report/report.rb', line 13 def chart @chart end |
#charts ⇒ Object
Returns the value of attribute charts.
13 14 15 |
# File 'lib/query_report/report.rb', line 13 def charts @charts end |
#current_scope ⇒ Object
Returns the value of attribute current_scope.
13 14 15 |
# File 'lib/query_report/report.rb', line 13 def current_scope @current_scope end |
#filters ⇒ Object
Returns the value of attribute filters.
13 14 15 |
# File 'lib/query_report/report.rb', line 13 def filters @filters end |
#options ⇒ Object
Returns the value of attribute options.
13 14 15 |
# File 'lib/query_report/report.rb', line 13 def end |
#params ⇒ Object
Returns the value of attribute params.
13 14 15 |
# File 'lib/query_report/report.rb', line 13 def params @params end |
#scopes ⇒ Object
Returns the value of attribute scopes.
13 14 15 |
# File 'lib/query_report/report.rb', line 13 def scopes @scopes end |
#template ⇒ Object
Returns the value of attribute template.
13 14 15 |
# File 'lib/query_report/report.rb', line 13 def template @template end |
Instance Method Details
#all_records ⇒ Object
62 63 64 |
# File 'lib/query_report/report.rb', line 62 def all_records @cached_all_records ||= map_record(query_without_pagination) end |
#compare_with_column_chart(title, x_axis = '', &block) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/query_report/report.rb', line 84 def compare_with_column_chart(title, x_axis='', &block) @chart = QueryReport::Chart::CustomChart.new(:column, title, query_without_pagination) @chart.add_column x_axis @chart.instance_eval &block if block_given? @charts << @chart end |
#map_record(query) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/query_report/report.rb', line 66 def map_record(query) query.clone.map do |record| array = @columns.collect { |column| [column.humanize, (column.data.kind_of?(Symbol) ? record.send(column.name) : column.data.call(record))] } Hash[*array.flatten] end end |
#model_name ⇒ Object
40 41 42 |
# File 'lib/query_report/report.rb', line 40 def model_name query.table.name.singularize end |
#pie_chart(title, &block) ⇒ Object
91 92 93 94 95 |
# File 'lib/query_report/report.rb', line 91 def pie_chart(title, &block) @chart = QueryReport::Chart::PieChart.new(title, query_without_pagination) @chart.instance_eval &block if block_given? @charts << @chart end |
#query ⇒ Object
48 49 50 51 |
# File 'lib/query_report/report.rb', line 48 def query apply_filters_and_pagination @query_cache end |
#query=(query) ⇒ Object
44 45 46 |
# File 'lib/query_report/report.rb', line 44 def query=(query) @query_cache = query end |
#query_without_pagination ⇒ Object
53 54 55 56 |
# File 'lib/query_report/report.rb', line 53 def query_without_pagination apply_filters_and_pagination @query_without_pagination_cache end |
#records ⇒ Object
58 59 60 |
# File 'lib/query_report/report.rb', line 58 def records @cached_records ||= map_record(query) end |
#scope(scope) ⇒ Object
74 75 76 77 |
# File 'lib/query_report/report.rb', line 74 def scope(scope) @scopes << scope @scopes = @scopes.uniq end |
#search ⇒ Object
79 80 81 82 |
# File 'lib/query_report/report.rb', line 79 def search apply_filters_and_pagination @search end |