Class: Core::Pipeline::Actions::Block

Inherits:
Core::Pipeline::Action show all
Includes:
Is::Inspectable
Defined in:
lib/core/pipeline/actions/block.rb

Overview

public

A pipeline action defined as a block.

Instance Attribute Summary

Attributes inherited from Core::Pipeline::Action

#after, #before, #name

Instance Method Summary collapse

Methods inherited from Core::Pipeline::Action

build, build_name, generate_random_suffix

Constructor Details

#initialize(name = nil, before: nil, after: nil, context: nil, &block) ⇒ Block

Returns a new instance of Block.



13
14
15
16
17
# File 'lib/core/pipeline/actions/block.rb', line 13

def initialize(name = nil, before: nil, after: nil, context: nil, &block)
  @block = block

  super(name, before: before, after: after, context: context)
end

Instance Method Details

#finalize(context) ⇒ Object

public


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/core/pipeline/actions/block.rb', line 21

def finalize(context)
  case @context
  when NilClass
    context.define_method(@name, &@block)
    @name
  else
    if @block.binding.receiver.equal?(@context)
      @block
    else
      @context.define_singleton_method(@name, &@block)
      @context.method(@name).to_proc
    end
  end
end