Module: Rails3::PluginExtender::Util

Included in:
LoadHandler, Matchers::BeExtendedWith
Defined in:
lib/plugin_toolbox/util.rb

Constant Summary collapse

INIT =
:initialize
ACTIVE_MODULES =
{:AR => :active_record, :view => :action_view, :controller => :action_controller, :mailer => :action_mailer}

Instance Method Summary collapse

Instance Method Details

#get_base_class(type) ⇒ Object



7
8
9
10
11
# File 'lib/plugin_toolbox/util.rb', line 7

def get_base_class type
  type = get_load_type(type).to_s
  return "#{type.to_s.camelize}::Base".constantize if type =~/action/ || type =~/active/
  "#{type.to_s.camelize}".constantize        
end

#get_constant(base_name, name) ⇒ Object



13
14
15
# File 'lib/plugin_toolbox/util.rb', line 13

def get_constant base_name, name   
  "#{base_name.to_s.camelize}::#{name.to_s.camelize}".constantize
end

#get_load_type(type) ⇒ Object



17
18
19
20
21
22
# File 'lib/plugin_toolbox/util.rb', line 17

def get_load_type type
   return ACTIVE_MODULES[type] if ACTIVE_MODULES[type]
   return type if ACTIVE_MODULES.values.include? type                
   return type if type == :i18n
   logger.warn "WARNING: The Rails 3 load handler for the component #{type} is not part of the default load process."
end

#get_module(module_name) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/plugin_toolbox/util.rb', line 24

def get_module module_name
  case module_name
  when Constant        
    module_name
  when String
    module_name.to_s.constantize
  else          
    raise ArgumentError, "#{module_name} could not be converted into a module constant"        
  end
end