Class: Noventius::Report
- Inherits:
-
Object
show all
- Includes:
- Dsl, Interpolator
- Defined in:
- lib/noventius/report.rb,
lib/noventius/report/dsl.rb,
lib/noventius/report/dsl/nested.rb,
lib/noventius/report/dsl/columns.rb,
lib/noventius/report/dsl/filters.rb,
lib/noventius/report/interpolator.rb,
lib/noventius/report/dsl/validations.rb,
lib/noventius/report/dsl/post_processors.rb
Defined Under Namespace
Modules: Dsl, Interpolator
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
included
Methods included from Dsl
included
Constructor Details
#initialize(filter_params = {}) ⇒ Report
Returns a new instance of Report.
30
31
32
|
# File 'lib/noventius/report.rb', line 30
def initialize(filter_params = {})
@filter_params = filter_params
end
|
Class Attribute Details
.tab_title ⇒ Object
Returns the value of attribute tab_title.
14
15
16
|
# File 'lib/noventius/report.rb', line 14
def tab_title
@tab_title
end
|
Class Method Details
.all ⇒ Object
34
35
36
37
38
|
# File 'lib/noventius/report.rb', line 34
def self.all
Dir.glob(File.expand_path('app/reports/*.rb', Rails.root)).map do |file|
file[%r{app\/reports\/(.*)\.rb}, 1].classify.constantize
end
end
|
.hidden(hidden) ⇒ Object
20
21
22
|
# File 'lib/noventius/report.rb', line 20
def hidden(hidden)
@hidden_flag = hidden
end
|
.title(title) ⇒ Object
16
17
18
|
# File 'lib/noventius/report.rb', line 16
def title(title)
@tab_title = title
end
|
.visible? ⇒ Boolean
24
25
26
|
# File 'lib/noventius/report.rb', line 24
def visible?
@hidden_flag.nil? || !@hidden_flag
end
|
.visibles ⇒ Object
40
41
42
|
# File 'lib/noventius/report.rb', line 40
def self.visibles
all.select(&:visible?)
end
|
Instance Method Details
#columns ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/noventius/report.rb', line 48
def columns
columns = super
columns = result.columns.map { |column| Column.new(column, :string) } unless columns.any?
columns
end
|
#processed_rows ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/noventius/report.rb', line 60
def processed_rows
post_processors.inject(rows) do |rows, (post_processor, options)|
execute = options.fetch(:if, true)
execute = instance_exec(&execute) if execute.is_a?(Proc)
execute = public_send(execute) if execute.is_a?(Symbol)
return rows unless execute
if post_processor.is_a?(Proc)
instance_exec(rows, &post_processor)
elsif post_processor.is_a?(Symbol)
public_send(post_processor, rows)
else
post_processor.process(self, rows)
end
end
end
|
#result ⇒ Object
44
45
46
|
# File 'lib/noventius/report.rb', line 44
def result
@result ||= ActiveRecord::Base.connection.exec_query(interpolate(sql))
end
|
#rows ⇒ Object
rubocop:disable Rails/Delegate
56
57
58
|
# File 'lib/noventius/report.rb', line 56
def rows
result.rows
end
|
#sql ⇒ Object
87
88
89
|
# File 'lib/noventius/report.rb', line 87
def sql
fail NotImplementedError, "Abstract method #{__method__}"
end
|
#to(format) ⇒ Object
78
79
80
81
82
83
84
85
|
# File 'lib/noventius/report.rb', line 78
def to(format)
case format
when :csv
Serializers::Csv.new(self).generate
else
fail NotImplementedError, "No serializer found for: #{format}"
end
end
|