Module: Legato::Model
- Defined in:
- lib/legato/model.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#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.
- #options_from_fields(fields) ⇒ Object
-
#results(profile, options = {}) ⇒ Query
Builds a ‘query` to get results from GA.
-
#segment(name, &block) ⇒ Proc
Define a segment.
- #segments ⇒ Object
-
#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
#dimensions(*fields) ⇒ ListParameter
Adds dimensions to the class for retrieval from GA
21 22 23 24 25 |
# File 'lib/legato/model.rb', line 21 def dimensions(*fields) fields, = (fields) @dimensions ||= ListParameter.new(:dimensions, [], .fetch(:tracking_scope, "ga")) @dimensions << fields end |
#filter(name, &block) ⇒ Proc
Define a filter
37 38 39 40 41 42 43 |
# File 'lib/legato/model.rb', line 37 def filter(name, &block) filters[name] = block (class << self; self; end).instance_eval do define_method(name) {|*args| Query.new(self).apply_filter(*args, &block)} end end |
#filters ⇒ Object
27 28 29 |
# File 'lib/legato/model.rb', line 27 def filters @filters ||= {} end |
#instance_klass ⇒ Object
72 73 74 |
# File 'lib/legato/model.rb', line 72 def instance_klass @instance_klass || OpenStruct end |
#metrics(*fields) ⇒ ListParameter
Adds metrics to the class for retrieval from GA
11 12 13 14 15 |
# File 'lib/legato/model.rb', line 11 def metrics(*fields) fields, = (fields) @metrics ||= ListParameter.new(:metrics, [], .fetch(:tracking_scope, "ga")) @metrics << fields end |
#options_from_fields(fields) ⇒ Object
94 95 96 97 |
# File 'lib/legato/model.rb', line 94 def (fields) = fields.pop if fields.last.is_a?(Hash) [fields, ( || {})] end |
#results(profile, options = {}) ⇒ Query
Builds a ‘query` to get results from GA
89 90 91 92 |
# File 'lib/legato/model.rb', line 89 def results(profile, = {}) # TODO: making tracking scope configurable when results are querried. not sure how to do this. Query.new(self).results(profile, ) end |
#segment(name, &block) ⇒ Proc
Define a segment
55 56 57 58 59 60 61 |
# File 'lib/legato/model.rb', line 55 def segment(name, &block) segments[name] = block (class << self; self; end).instance_eval do define_method(name) {|*args| Query.new(self).apply_segment_filter(*args, &block)} end end |
#segments ⇒ Object
45 46 47 |
# File 'lib/legato/model.rb', line 45 def segments @segments ||= {} end |
#set_instance_klass(klass) ⇒ Object
Set the class used to make new instances of returned results from GA
68 69 70 |
# File 'lib/legato/model.rb', line 68 def set_instance_klass(klass) @instance_klass = klass end |