Class: Report
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#queries ⇒ Object
readonly
Returns the value of attribute queries.
Class Method Summary collapse
-
.all ⇒ Object
todo: change this to reports.
- .find_by_name(name) ⇒ Object
Instance Method Summary collapse
- #allow_partial_match? ⇒ Boolean
-
#css_class_name ⇒ Object
todo: think this over, models are probably not a good place for the css class name.
- #current? ⇒ Boolean
-
#initialize(name, opts = {}) ⇒ Report
constructor
A new instance of Report.
- #query(name, &block) ⇒ Object
-
#query_objects ⇒ Object
todo: change this to queries.
- #require_search? ⇒ Boolean
- #show_all_on_load ⇒ Object
- #show_all_on_load? ⇒ Boolean
- #to_h ⇒ Object
- #url ⇒ Object
- #view_name ⇒ Object
Methods included from Attribute
Constructor Details
#initialize(name, opts = {}) ⇒ Report
Returns a new instance of Report.
28 29 30 31 32 33 |
# File 'lib/athergin/report.rb', line 28 def initialize(name,opts={}) @name = name @namespace = opts[:namespace] @queries = {} @show_all_on_load = false end |
Instance Attribute Details
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
3 4 5 |
# File 'lib/athergin/report.rb', line 3 def namespace @namespace end |
#queries ⇒ Object (readonly)
Returns the value of attribute queries.
3 4 5 |
# File 'lib/athergin/report.rb', line 3 def queries @queries end |
Class Method Details
.all ⇒ Object
todo: change this to reports
19 20 21 |
# File 'lib/athergin/report.rb', line 19 def all Namespace.all.map(&:report_objects).flatten end |
.find_by_name(name) ⇒ Object
23 24 25 |
# File 'lib/athergin/report.rb', line 23 def find_by_name(name) all.find { |report| report.name == name.try(:to_sym) } end |
Instance Method Details
#allow_partial_match? ⇒ Boolean
63 64 65 |
# File 'lib/athergin/report.rb', line 63 def allow_partial_match? query_objects.select { |query| query.allow_partial_match? }.present? end |
#css_class_name ⇒ Object
todo: think this over, models are probably not a good place for the css class name
76 77 78 |
# File 'lib/athergin/report.rb', line 76 def css_class_name current? ? 'active' : 'inactive' end |
#current? ⇒ Boolean
71 72 73 |
# File 'lib/athergin/report.rb', line 71 def current? name.eql? Platform.current_report.name end |
#query(name, &block) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/athergin/report.rb', line 44 def query(name, &block) warn "warning: overriding query '#{ name }'" if @queries[name] @queries[name] = Query.new name @queries[name].instance_eval &block end |
#query_objects ⇒ Object
todo: change this to queries
36 37 38 |
# File 'lib/athergin/report.rb', line 36 def query_objects queries.values end |
#require_search? ⇒ Boolean
55 56 57 |
# File 'lib/athergin/report.rb', line 55 def require_search? !show_all_on_load? end |
#show_all_on_load ⇒ Object
51 52 53 |
# File 'lib/athergin/report.rb', line 51 def show_all_on_load @show_all_on_load = true end |
#show_all_on_load? ⇒ Boolean
59 60 61 |
# File 'lib/athergin/report.rb', line 59 def show_all_on_load? @show_all_on_load end |
#to_h ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/athergin/report.rb', line 6 def to_h methods = [:name, :description, :url, :current?, :css_class_name] methods.map do |method| key, value = method.to_s.gsub(/\?$/,'').to_sym, send(method) value = '' if value.nil? value = value.to_data if value.is_a? Array [key, value] end.to_h end |
#url ⇒ Object
40 41 42 |
# File 'lib/athergin/report.rb', line 40 def url "/reports/#{ name }" end |
#view_name ⇒ Object
67 68 69 |
# File 'lib/athergin/report.rb', line 67 def view_name :report end |