Class: Analytical::Api
- Inherits:
-
Object
- Object
- Analytical::Api
- Defined in:
- lib/analytical/api.rb
Defined Under Namespace
Classes: ImmediateDelegateHelper
Instance Attribute Summary collapse
-
#modules ⇒ Object
Returns the value of attribute modules.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #body_append_javascript ⇒ Object
- #body_prepend_javascript ⇒ Object
- #head_append_javascript ⇒ Object (also: #head_javascript)
-
#head_prepend_javascript ⇒ Object
These methods return the javascript that should be inserted into each section of your layout.
-
#initialize(options = {}) ⇒ Api
constructor
A new instance of Api.
-
#method_missing(method, *args, &block) ⇒ Object
Catch commands such as :track, :identify and send them on to all of the modules.
-
#now ⇒ Object
Returns a new delegation object for immediate processing of a command.
Constructor Details
#initialize(options = {}) ⇒ Api
Returns a new instance of Api.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/analytical/api.rb', line 12 def initialize(={}) @options = @modules = @options[:modules].inject(ActiveSupport::OrderedHash.new) do |h, m| = @options.merge(@options[m] || {}) .delete(:modules) [:session_store] = Analytical::SessionCommandStore.new(@options[:session], m) if @options[:session] h[m] = "Analytical::Modules::#{m.to_s.camelize}".constantize.new() h end @dummy_module = Analytical::Modules::DummyModule.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Catch commands such as :track, :identify and send them on to all of the modules. Or… if a module name is passed, return that module so it can be used directly, ie: analytical.console.go ‘make’, :some=>:cookies
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/analytical/api.rb', line 29 def method_missing(method, *args, &block) method = method.to_sym if @modules.keys.include?(method) @modules[method] elsif available_modules.include?(method) @dummy_module else process_command method, *args end end |
Instance Attribute Details
#modules ⇒ Object
Returns the value of attribute modules.
10 11 12 |
# File 'lib/analytical/api.rb', line 10 def modules @modules end |
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/analytical/api.rb', line 10 def @options end |
Instance Method Details
#body_append_javascript ⇒ Object
78 79 80 |
# File 'lib/analytical/api.rb', line 78 def body_append_javascript [init_javascript(:body_append), tracking_javascript(:body_append)].delete_if{|s| s.blank?}.join("\n") end |
#body_prepend_javascript ⇒ Object
75 76 77 |
# File 'lib/analytical/api.rb', line 75 def body_prepend_javascript [init_javascript(:body_prepend), tracking_javascript(:body_prepend)].delete_if{|s| s.blank?}.join("\n") end |
#head_append_javascript ⇒ Object Also known as: head_javascript
69 70 71 |
# File 'lib/analytical/api.rb', line 69 def head_append_javascript [init_javascript(:head_append), tracking_javascript(:head_append)].delete_if{|s| s.blank?}.join("\n") end |
#head_prepend_javascript ⇒ Object
These methods return the javascript that should be inserted into each section of your layout
65 66 67 |
# File 'lib/analytical/api.rb', line 65 def head_prepend_javascript [init_javascript(:head_prepend), tracking_javascript(:head_prepend)].delete_if{|s| s.blank?}.join("\n") end |
#now ⇒ Object
Returns a new delegation object for immediate processing of a command
58 59 60 |
# File 'lib/analytical/api.rb', line 58 def now ImmediateDelegateHelper.new(self) end |