Class: Rails::Initializable::Initializer

Inherits:
Object
  • Object
show all
Defined in:
railties/lib/rails/initializable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, context, options, &block) ⇒ Initializer

Returns a new instance of Initializer.


14
15
16
17
# File 'railties/lib/rails/initializable.rb', line 14

def initialize(name, context, options, &block)
  options[:group] ||= :default
  @name, @context, @options, @block = name, context, options, block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block


12
13
14
# File 'railties/lib/rails/initializable.rb', line 12

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name


12
13
14
# File 'railties/lib/rails/initializable.rb', line 12

def name
  @name
end

Instance Method Details

#afterObject


23
24
25
# File 'railties/lib/rails/initializable.rb', line 23

def after
  @options[:after]
end

#beforeObject


19
20
21
# File 'railties/lib/rails/initializable.rb', line 19

def before
  @options[:before]
end

#belongs_to?(group) ⇒ Boolean

Returns:

  • (Boolean)

27
28
29
# File 'railties/lib/rails/initializable.rb', line 27

def belongs_to?(group)
  @options[:group] == group || @options[:group] == :all
end

#bind(context) ⇒ Object


35
36
37
38
# File 'railties/lib/rails/initializable.rb', line 35

def bind(context)
  return self if @context
  Initializer.new(@name, context, @options, &block)
end

#context_classObject


40
41
42
# File 'railties/lib/rails/initializable.rb', line 40

def context_class
  @context.class
end

#run(*args) ⇒ Object


31
32
33
# File 'railties/lib/rails/initializable.rb', line 31

def run(*args)
  @context.instance_exec(*args, &block)
end