Class: Pakyow::Support::Pipeline::Action Private

Inherits:
Object
  • Object
show all
Defined in:
lib/pakyow/support/pipeline.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, *options, &block) ⇒ Action

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Action.



287
288
289
290
291
292
293
# File 'lib/pakyow/support/pipeline.rb', line 287

def initialize(target, *options, &block)
  @target, @options, @block = target, options, block

  if target.is_a?(Symbol)
    @name = target
  end
end

Instance Attribute Details

#nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



285
286
287
# File 'lib/pakyow/support/pipeline.rb', line 285

def name
  @name
end

#optionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



285
286
287
# File 'lib/pakyow/support/pipeline.rb', line 285

def options
  @options
end

#targetObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



285
286
287
# File 'lib/pakyow/support/pipeline.rb', line 285

def target
  @target
end

Instance Method Details

#finalize(context = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/pakyow/support/pipeline.rb', line 295

def finalize(context = nil)
  if @block
    if context
      if @block.arity == 0
        Proc.new do
          context.instance_exec(&@block)
        end
      else
        Proc.new do |object|
          context.instance_exec(object, &@block)
        end
      end
    else
      @block
    end
  elsif @target.is_a?(Symbol) && context.respond_to?(@target, true) && (options[0].nil? || !options[0].instance_methods(false).include?(:call))
    if context
      context.method(@target)
    else
      raise "finalizing pipeline action #{@target} requires context"
    end
  else
    target, target_options = if @target.is_a?(Symbol)
      [@options[0], @options[1..-1]]
    else
      [@target, @options]
    end

    instance = if target.is_a?(Class)
      target.new(*target_options)
    else
      target
    end

    instance.method(:call)
  end
end