Module: RuportReportBuilder::ClassMethods

Defined in:
lib/ruport_report_builder.rb

Instance Method Summary collapse

Instance Method Details

#define_report(name, query = nil, &proc) ⇒ Object

Raises:

  • (ArgumentError)


64
65
66
67
68
# File 'lib/ruport_report_builder.rb', line 64

def define_report(name, query = nil, &proc)
  raise ArgumentError, "The report name [name] is incorrect.  Report names must not contain a space!" if name.to_s.empty? || name.to_s.include?(" ")
  raise ArgumentError, "You must provide a query or properly name it as a method. Looking for #{query_method_name(name)}. !!If using a query method, make sure it is defined *above* the report definition!!" if query.nil? && !self.instance_methods.include?(query_method_name(name))
  reports[name] = {:query => query, :action => proc}
end

#query_method_name(name) ⇒ Object



74
75
76
# File 'lib/ruport_report_builder.rb', line 74

def query_method_name(name)
  "#{name.gsub(/\s/, "_")}_query"
end

#report(name) ⇒ Object



70
71
72
# File 'lib/ruport_report_builder.rb', line 70

def report(name)
  reports[name]
end

#report_namesObject



60
61
62
# File 'lib/ruport_report_builder.rb', line 60

def report_names
  reports.keys
end

#reportsObject



56
57
58
# File 'lib/ruport_report_builder.rb', line 56

def reports
  @reports ||= RuportReportBuilderUtil::OrderedHash.new
end