Module: Legato::Model
- Defined in:
- lib/legato/model.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_method_to_set(name, type, &block) ⇒ Object
-
#dimensions(*fields) ⇒ ListParameter
Adds dimensions to the class for retrieval from GA.
-
#filter(name, &block) ⇒ Proc
Define a filter.
- #filters ⇒ Object
- #instance_klass ⇒ Object
-
#metrics(*fields) ⇒ ListParameter
Adds metrics to the class for retrieval from GA.
-
#realtime ⇒ Query
Builds a ‘query` and sets the `realtime` property.
-
#results(profile, options = {}) ⇒ Query
Builds a ‘query` to get results from GA.
-
#segment(name, &block) ⇒ Proc
Define a segment.
- #segments ⇒ Object (also: #segment_filters)
-
#set_instance_klass(klass) ⇒ Object
Set the class used to make new instances of returned results from GA.
Class Method Details
.extended(base) ⇒ Object
3 4 5 |
# File 'lib/legato/model.rb', line 3 def self.extended(base) ProfileMethods.add_profile_method(base) end |
Instance Method Details
#add_method_to_set(name, type, &block) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/legato/model.rb', line 93 def add_method_to_set(name, type, &block) send(type)[name] = block (class << self; self; end).instance_eval do define_method(name) {|*args| Query.new(self).apply_filter_expression(type, *args, &block)} end end |
#dimensions(*fields) ⇒ ListParameter
Adds dimensions to the class for retrieval from GA
20 21 22 23 |
# File 'lib/legato/model.rb', line 20 def dimensions(*fields) @dimensions ||= ListParameter.new(:dimensions, []) @dimensions << fields end |
#filter(name, &block) ⇒ Proc
Define a filter
35 36 37 |
# File 'lib/legato/model.rb', line 35 def filter(name, &block) add_method_to_set(name, :filters, &block) end |
#filters ⇒ Object
25 26 27 |
# File 'lib/legato/model.rb', line 25 def filters @filters ||= {} end |
#instance_klass ⇒ Object
63 64 65 |
# File 'lib/legato/model.rb', line 63 def instance_klass @instance_klass || OpenStruct end |
#metrics(*fields) ⇒ ListParameter
Adds metrics to the class for retrieval from GA
11 12 13 14 |
# File 'lib/legato/model.rb', line 11 def metrics(*fields) @metrics ||= ListParameter.new(:metrics, []) @metrics << fields end |
#realtime ⇒ Query
Builds a ‘query` and sets the `realtime` property
89 90 91 |
# File 'lib/legato/model.rb', line 89 def realtime Query.new(self).realtime end |
#results(profile, options = {}) ⇒ Query
Builds a ‘query` to get results from GA
81 82 83 84 |
# File 'lib/legato/model.rb', line 81 def results(profile, = {}) # TODO: making tracking scope configurable when results are querried. not sure how to do this. Query.new(self).(.merge(:profile => profile)) end |
#segment(name, &block) ⇒ Proc
Define a segment
50 51 52 |
# File 'lib/legato/model.rb', line 50 def segment(name, &block) add_method_to_set(name, :segment_filters, &block) end |
#segments ⇒ Object Also known as: segment_filters
39 40 41 |
# File 'lib/legato/model.rb', line 39 def segments @segments ||= {} end |
#set_instance_klass(klass) ⇒ Object
Set the class used to make new instances of returned results from GA
59 60 61 |
# File 'lib/legato/model.rb', line 59 def set_instance_klass(klass) @instance_klass = klass end |