Class: Rails3::PluginExtender

Inherits:
Object
  • Object
show all
Includes:
LoadHandler
Defined in:
lib/plugin_toolbox/util.rb,
lib/plugin_toolbox/loader.rb,
lib/plugin_toolbox/extender.rb,
lib/plugin_toolbox/rspec/macro.rb,
lib/plugin_toolbox/rspec/matchers/be_extended_with.rb

Defined Under Namespace

Modules: DSL, LoadHandler, Macro, Matchers, Util

Constant Summary

Constants included from Util

Util::ACTIVE_MODULES, Util::INIT

Instance Method Summary collapse

Methods included from LoadHandler

#after, #before, #load_handling, #on_load

Methods included from Util

#act_type?, #get_base_class, #get_constant, #get_load_type, #get_module, #make_constant, #rails_const_base

Constructor Details

#initialize(&block) ⇒ PluginExtender

Returns a new instance of PluginExtender.



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

def initialize &block
  if block
    block.arity < 1 ? self.instance_eval(&block) : block.call(self)  
  end      
end

Instance Method Details

#extend_from_module(base_name, *module_names, options) ⇒ Object

convenience method to extend with multiple modules all within the same base module

Raises:

  • (ArgumentError)


20
21
22
23
24
25
# File 'lib/plugin_toolbox/extender.rb', line 20

def extend_from_module base_name, *module_names, options
  raise ArgumentError, "You must specify an options Hash as the last argument for #extend_from_module" if !options.kind_of? Hash      
  module_names.each do |name|
    extend_with get_constant(base_name, name), options
  end
end

#extend_rails(type, &block) ⇒ Object

load after: [:initialize, :configuration, :eager_load]



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

def extend_rails(type, &block)
  on_load(type, &block)
end

#extend_with(*module_names, options) ⇒ Object

Raises:

  • (ArgumentError)


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

def extend_with *module_names, options
  raise ArgumentError, "You must specify an options Hash as the last argument for #extend_with" if !options.kind_of? Hash      
  type = options[:in]
  raise ArgumentError, "You must specify an :in option to indicate which Rails 3 component base class to extend with #{module_names}" if !type
  module_names.each do |name|      
    extend! name, type
  end
end