Class: AnalyticsMapping
- Inherits:
-
Object
- Object
- AnalyticsMapping
- Defined in:
- lib/analytics_instrumentation/analytics_mapping.rb
Constant Summary collapse
- @@mappings =
AnalyticsMapping.createMappings
Class Method Summary collapse
- .createMappings ⇒ Object
- .replaceAllTokens(obj, params, view_assigns) ⇒ Object
- .replaceTokens(str, params, view_assigns) ⇒ Object
- .to_event(params, view_assigns) ⇒ Object
Class Method Details
.createMappings ⇒ Object
2 3 4 5 6 7 8 9 10 11 |
# File 'lib/analytics_instrumentation/analytics_mapping.rb', line 2 def self.createMappings # TODO: Reload this on Rails Auto-reload mappings = {} @mappingFiles = Dir.glob("config/analytics/*.yml") for file in @mappingFiles yaml = YAML.load_file(file) mappings.merge! yaml end mappings end |
.replaceAllTokens(obj, params, view_assigns) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/analytics_instrumentation/analytics_mapping.rb', line 28 def self.replaceAllTokens(obj, params, view_assigns) if obj.is_a? String replaceTokens(obj, params, view_assigns) elsif obj.is_a? Hash obj.each {|k, v| replaceAllTokens(v, params, view_assigns)} end end |
.replaceTokens(str, params, view_assigns) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/analytics_instrumentation/analytics_mapping.rb', line 36 def self.replaceTokens(str, params, view_assigns) return if str["@"].nil? && str["params["].nil? properties = {} view_assigns.each {|k, v| properties.instance_variable_set "@#{k}", v} properties["params"] = params result = ERB.new("<%= #{str} %>").result(properties.instance_eval {binding}) str[0..-1] = result end |
.to_event(params, view_assigns) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/analytics_instrumentation/analytics_mapping.rb', line 15 def self.to_event(params, view_assigns) methodName = "#{params[:controller]}##{params[:action]}" analysis = @@mappings[methodName] return nil if analysis.nil? replaceAllTokens(analysis, params, view_assigns) analysis[:parameters] ||= {} HashWithIndifferentAccess.new(analysis) end |