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
92 93 94 |
# File 'lib/analytical/api.rb', line 92 def body_append_javascript [init_javascript(:body_append), tracking_javascript(:body_append)].delete_if{|s| s.blank?}.join("\n") end |
#body_prepend_javascript ⇒ Object
89 90 91 |
# File 'lib/analytical/api.rb', line 89 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/analytical/api.rb', line 69 def head_append_javascript js = [ init_javascript(:head_append), tracking_javascript(:head_append), ] if [:javascript_helpers] if ::Rails::VERSION::STRING.to_i >= 3.1 # Rails 3.1 lets us override views in engines js << [:controller].send(:render_to_string, :partial=>'analytical_javascript') if [:controller] else # All other rails _partial_path = Pathname.new(__FILE__).dirname.join('..', '..', 'app/views/application', '_analytical_javascript.html.erb').to_s js << [:controller].send(:render_to_string, :file=>_partial_path, :layout=>false) if [:controller] end end js.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 |