Module: Lolita::Extensions

Defined in:
lib/lolita/extensions/extensions.rb,
lib/lolita/extensions/authorization/proxy.rb,
lib/lolita/extensions/authentication/proxy.rb,
lib/lolita/extensions/authorization/cancan_adapter.rb,
lib/lolita/extensions/authorization/pundit_adapter.rb,
lib/lolita/extensions/authentication/devise_adapter.rb,
lib/lolita/extensions/authorization/default_adapter.rb,
lib/lolita/extensions/authentication/default_adapter.rb

Overview

This module provides functionality for extension machinery in Lolita. It loads proxies on demand.

Defined Under Namespace

Modules: Authentication, Authorization

Constant Summary collapse

EXTENSIONS =
[]

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/lolita/extensions/extensions.rb', line 6

def method_missing method_name, *args, &block
  if method_name[/_proxy$/]
    type = method_name.to_s.sub(/_proxy$/,"")
    self.class_eval <<-EXTENSION,__FILE__,__LINE__+1
      def #{method_name}(*args,&block)
        unless __extensions_proxies[:#{type}]
          load_extension_proxy(:#{type},self,__proxy_options_from_context)
        end
        __extensions_proxies[:#{type}]
      end
    EXTENSION
    send(method_name)
  else
    super
  end
end

Class Method Details

.add(type) ⇒ Object



41
42
43
# File 'lib/lolita/extensions/extensions.rb', line 41

def self.add type
  EXTENSIONS << type unless EXTENSIONS.include?(type)
end

Instance Method Details

#load_extension_proxy(type, context = self, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/lolita/extensions/extensions.rb', line 29

def load_extension_proxy type,context=self,options={}
  proxy_class = "Lolita::Extensions::#{type.to_s.camelize}::Proxy".constantize
  initialize_arity = proxy_class.instance_method(:initialize).arity
  __extensions_proxies[type] = if initialize_arity < 0 || initialize_arity > 1
    proxy_class.new(context,options)
  elsif initialize_arity == 0
    proxy_class.new
  else
    proxy_class.new(context)
  end
end

#load_extensions_proxies(context = self, options = {}) ⇒ Object



23
24
25
26
27
# File 'lib/lolita/extensions/extensions.rb', line 23

def load_extensions_proxies(context=self, options={})
  EXTENSIONS.each do |type|
    load_extension_proxy(type,context,options)
  end
end