Class: Rails3::Plugin::Extender

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

Defined Under Namespace

Modules: DSL, LoadHandler, Macro, Matchers, Util

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) ⇒ Extender

Returns a new instance of Extender.



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

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) ⇒ Object

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

Raises:

  • (ArgumentError)


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

def extend_from_module base_name, *module_names
  options = last_option(module_names)
  raise ArgumentError, "You must specify an options Hash as the last argument for #extend_from_module" if !options || !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]



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

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

#extend_with(*module_names) ⇒ Object

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
43
44
# File 'lib/r3_plugin_toolbox/extender.rb', line 36

def extend_with *module_names
  options = last_option(module_names)
  raise ArgumentError, "You must specify an options Hash as the last argument for #extend_with" if !options || !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

#with_configuration(&block) ⇒ Object



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

def with_configuration &block
  if block
    block.arity < 1 ? Rails.configuration.instance_eval(&block) : block.call(Rails.configuration)  
  end      
end