Module: Compendium::DSL
- Included in:
- Report
- Defined in:
- lib/compendium/dsl.rb
Class Method Summary
collapse
Instance Method Summary
collapse
-
#method_missing(name, *args, &block) ⇒ Object
Allow defined queries to be redefined by name, eg: query :main_query main_query { collect_records_here }.
-
#metric(name, proc, opts = {}) ⇒ Object
-
#option(name, *args) ⇒ Object
-
#query(name, opts = {}, &block) ⇒ Object
(also: #chart, #data)
-
#respond_to_missing?(name, *args) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Allow defined queries to be redefined by name, eg: query :main_query main_query { collect_records_here }
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/compendium/dsl.rb', line 43
def method_missing(name, *args, &block)
if queries.keys.include?(name.to_sym)
query = queries[name.to_sym]
query.proc = block if block_given?
query.options = args.
return query
end
super
end
|
Class Method Details
.extended(klass) ⇒ Object
8
9
10
11
|
# File 'lib/compendium/dsl.rb', line 8
def self.extended(klass)
klass.inheritable_attr :queries, default: ::Collection[Query]
klass.inheritable_attr :options, default: {}
end
|
Instance Method Details
#metric(name, proc, opts = {}) ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/compendium/dsl.rb', line 31
def metric(name, proc, opts = {})
raise ArgumentError, 'through option must be specified for metric' unless opts.key?(:through)
[opts.delete(:through)].flatten.each do |query|
raise ArgumentError, "query #{query} is not defined" unless queries.key?(query)
queries[query].add_metric(name, proc, opts)
end
end
|
#option(name, *args) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/compendium/dsl.rb', line 19
def option(name, *args)
opts = args.
type = args.shift
if options[name]
options[name].type = type if type
options[name].merge!(opts)
else
options[name] = Compendium::Option.new(opts.merge(name: name, type: type))
end
end
|
#query(name, opts = {}, &block) ⇒ Object
Also known as:
chart, data
13
14
15
|
# File 'lib/compendium/dsl.rb', line 13
def query(name, opts = {}, &block)
define_query(name, opts, &block)
end
|
#respond_to_missing?(name, *args) ⇒ Boolean
54
55
56
57
|
# File 'lib/compendium/dsl.rb', line 54
def respond_to_missing?(name, *args)
return true if queries.keys.include?(name)
super
end
|