Module: Rails3::PluginExtender::Util

Included in:
LoadHandler, Macro, 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

#act_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


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

def act_type? type
  type =~/action/ || type =~/active/        
end

#get_base_class(type) ⇒ Object



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

def get_base_class type
  type = get_load_type(type).to_s
  const = act_type?(type) ? rails_const_base(type) : "#{type.to_s.camelize}"                            
end

#get_constant(base_name, name) ⇒ Object



16
17
18
# File 'lib/plugin_toolbox/util.rb', line 16

def get_constant base_name, name   
  make_constant(base_name, name).constantize
end

#get_load_type(type) ⇒ Object



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

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



35
36
37
38
39
40
41
42
43
44
# File 'lib/plugin_toolbox/util.rb', line 35

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

#make_constant(base_name, name) ⇒ Object



24
25
26
# File 'lib/plugin_toolbox/util.rb', line 24

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

#rails_const_base(type) ⇒ Object



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

def rails_const_base type
  "#{type.to_s.camelize}::Base"
end