Module: Rails3::Plugin::Extender::Util
- Included in:
- LoadHandler, Macro, Matchers::BeExtendedWith
- Defined in:
- lib/r3_plugin_toolbox/extender/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
13 14 15 |
# File 'lib/r3_plugin_toolbox/extender/util.rb', line 13 def act_type? type type =~/action/ || type =~/active/ end |
#get_base_class(type) ⇒ Object
8 9 10 11 |
# File 'lib/r3_plugin_toolbox/extender/util.rb', line 8 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
17 18 19 |
# File 'lib/r3_plugin_toolbox/extender/util.rb', line 17 def get_constant base_name, name make_constant(base_name, name).constantize end |
#get_load_type(type) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/r3_plugin_toolbox/extender/util.rb', line 29 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
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/r3_plugin_toolbox/extender/util.rb', line 36 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
25 26 27 |
# File 'lib/r3_plugin_toolbox/extender/util.rb', line 25 def make_constant base_name, name "#{base_name.to_s.camelize}::#{name.to_s.camelize}" end |
#rails_const_base(type) ⇒ Object
21 22 23 |
# File 'lib/r3_plugin_toolbox/extender/util.rb', line 21 def rails_const_base type "#{type.to_s.camelize}::Base" end |