Class: Report

Inherits:
Object
  • Object
show all
Extended by:
Attribute
Defined in:
lib/athergin/report.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Attribute

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

#namespaceObject (readonly)

Returns the value of attribute namespace.



3
4
5
# File 'lib/athergin/report.rb', line 3

def namespace
  @namespace
end

#queriesObject (readonly)

Returns the value of attribute queries.



3
4
5
# File 'lib/athergin/report.rb', line 3

def queries
  @queries
end

Class Method Details

.allObject

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

Returns:

  • (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_nameObject

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

Returns:

  • (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_objectsObject

todo: change this to queries



36
37
38
# File 'lib/athergin/report.rb', line 36

def query_objects
  queries.values
end

#require_search?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/athergin/report.rb', line 55

def require_search?
  !show_all_on_load?
end

#show_all_on_loadObject



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

Returns:

  • (Boolean)


59
60
61
# File 'lib/athergin/report.rb', line 59

def show_all_on_load?
  @show_all_on_load
end

#to_hObject



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

#urlObject



40
41
42
# File 'lib/athergin/report.rb', line 40

def url
  "/reports/#{ name }"
end

#view_nameObject



67
68
69
# File 'lib/athergin/report.rb', line 67

def view_name
  :report
end