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
- #act_type?(type) ⇒ Boolean
- #get_base_class(type) ⇒ Object
- #get_constant(base_name, name) ⇒ Object
- #get_load_type(type) ⇒ Object
- #get_module(module_name) ⇒ Object
- #make_constant(base_name, name) ⇒ Object
- #rails_const_base(type) ⇒ Object
Instance Method Details
#act_type?(type) ⇒ Boolean
17 18 19 |
# File 'lib/plugin_toolbox/util.rb', line 17 def act_type? type type =~/action/ || type =~/active/ end |
#get_base_class(type) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/plugin_toolbox/util.rb', line 7 def get_base_class type begin type = get_load_type(type).to_s const = act_type?(type) ? rails_const_base(type) : "#{type.to_s.camelize}" const.constantize rescue raise ArgumentError, "Can't find rails constant: #{const}" end end |
#get_constant(base_name, name) ⇒ Object
21 22 23 |
# File 'lib/plugin_toolbox/util.rb', line 21 def get_constant base_name, name make_constant(base_name, name).constantize end |
#get_load_type(type) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/plugin_toolbox/util.rb', line 33 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
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/plugin_toolbox/util.rb', line 40 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
29 30 31 |
# File 'lib/plugin_toolbox/util.rb', line 29 def make_constant base_name, name "#{base_name.to_s.camelize}::#{name.to_s.camelize}" end |
#rails_const_base(type) ⇒ Object
25 26 27 |
# File 'lib/plugin_toolbox/util.rb', line 25 def rails_const_base type "#{type.to_s.camelize}::Base" end |