Module: Reportly::ConsoleMethods
Defined Under Namespace
Classes: ReportlyNotValid
Instance Method Summary
collapse
Instance Method Details
#is_valid_klass?(model) ⇒ Boolean
accepts Array or a ActiveRecord_Relation Should respond_to? :each and be descend from active record
50
51
52
|
# File 'lib/reportly/console_methods.rb', line 50
def is_valid_klass?(model)
model.first.class.descends_from_active_record? rescue false and model.respond_to? :each
end
|
#make_array_for(model) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/reportly/console_methods.rb', line 23
def make_array_for(model)
model = [model] if model.class.superclass == ActiveRecord::Base
model = model.send(:all) if model.class.name == 'Class' and model.respond_to? :all
model
end
|
#report(model, *fields) ⇒ Object
9
10
11
12
13
14
15
16
17
|
# File 'lib/reportly/console_methods.rb', line 9
def report(model, *fields)
model = make_array_for(model)
validate(model)
report = Reportly::Engine.report(model, *fields)
@results = report
puts report.join("\n")
end
|
#results ⇒ Object
19
20
21
|
# File 'lib/reportly/console_methods.rb', line 19
def results
@results
end
|
#validate(model) ⇒ Object
44
45
46
|
# File 'lib/reportly/console_methods.rb', line 44
def validate(model)
raise ReportlyNotValid, "Reportly accepts only ActiveRecord Objects" unless is_valid_klass?(model)
end
|