Class: Rails::Initializable::Initializer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, context, before:, after:, group: nil, &block) ⇒ Initializer

Returns a new instance of Initializer.



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

def initialize(name, context, before:, after:, group: nil, &block)
  @group = group || :default
  @name, @before, @after, @context, @block = name, before, after, context, block
end

Instance Attribute Details

#afterObject (readonly)

Returns the value of attribute after.



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

def after
  @after
end

#beforeObject (readonly)

Returns the value of attribute before.



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

def before
  @before
end

#blockObject (readonly)

Returns the value of attribute block.



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

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#belongs_to?(group) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#bind(context) ⇒ Object



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

def bind(context)
  return self if @context
  Initializer.new(@name, context, before:, after:, group: @group, &block)
end

#context_classObject



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

def context_class
  @context.class
end

#run(*args) ⇒ Object



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

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