Module: Piwik::ApiScope::ClassMethods

Defined in:
lib/piwik/api_scope.rb

Instance Method Summary collapse

Instance Method Details

#api_scope(name, scope_options = {}, &block) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/piwik/api_scope.rb', line 16

def api_scope name, scope_options = {}, &block
  name = name.to_sym
  class_name = "Piwik::#{scope_options[:class_name] ? scope_options[:class_name] : name.to_s.camelize}"
  extension =  Module.new(&Proc.new) if block_given?
  instance_eval do          
    define_method name do
      klass = class_name.constantize
      klass.extend(extension) if block_given?
      klass.instance_variable_set(:@obj, self)
      klass
    end
  end
  self
end