Module: Rails3::Plugin::Extender::Util

Included in:
LoadHandler, Macro, Matchers::BeExtendedWith
Defined in:
lib/r3_plugin_toolbox/extender/util.rb

Instance Method Summary collapse

Instance Method Details

#act_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/r3_plugin_toolbox/extender/util.rb', line 10

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

#get_base_class(type) ⇒ Object



5
6
7
8
# File 'lib/r3_plugin_toolbox/extender/util.rb', line 5

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



14
15
16
# File 'lib/r3_plugin_toolbox/extender/util.rb', line 14

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

#get_load_type(type) ⇒ Object



26
27
28
29
30
31
# File 'lib/r3_plugin_toolbox/extender/util.rb', line 26

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



33
34
35
36
37
38
39
40
41
42
# File 'lib/r3_plugin_toolbox/extender/util.rb', line 33

def get_module module_name
  case module_name
  when Module        
    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



22
23
24
# File 'lib/r3_plugin_toolbox/extender/util.rb', line 22

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

#rails_const_base(type) ⇒ Object



18
19
20
# File 'lib/r3_plugin_toolbox/extender/util.rb', line 18

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