Class: Rails::Initializable::Initializer
- Inherits:
-
Object
- Object
- Rails::Initializable::Initializer
- Defined in:
- lib/rails/initializable.rb
Instance Attribute Summary collapse
-
#after ⇒ Object
readonly
Returns the value of attribute after.
-
#before ⇒ Object
readonly
Returns the value of attribute before.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #belongs_to?(group) ⇒ Boolean
- #bind(context) ⇒ Object
- #context_class ⇒ Object
-
#initialize(name, context, before:, after:, group: nil, &block) ⇒ Initializer
constructor
A new instance of Initializer.
- #run(*args) ⇒ Object
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
#after ⇒ Object (readonly)
Returns the value of attribute after.
12 13 14 |
# File 'lib/rails/initializable.rb', line 12 def after @after end |
#before ⇒ Object (readonly)
Returns the value of attribute before.
12 13 14 |
# File 'lib/rails/initializable.rb', line 12 def before @before end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
12 13 14 |
# File 'lib/rails/initializable.rb', line 12 def block @block end |
#name ⇒ Object (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
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_class ⇒ Object
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 |