module Actions::Action

Public Class Methods

included(base) click to toggle source
# File lib/actions/action.rb, line 10
def self.included(base)
  base.class_eval do
    prepend Storage
    prepend ErrorHandling
    extend ClassMethods
    attr_reader :context
  end
end
new(context = {}) click to toggle source

FIXME: Handle context failures more gracefully, i.e. don’t initialize a new action if one in the group failed previously.

# File lib/actions/action.rb, line 45
def initialize(context = {})
  @context = SafeContext.new(context)
  if @context.success? && (self.class.inputs.any? || self.class.outputs.any?)
    @context.action = self
    self.class.inputs.each do |name, options|
      @context.input!(name, type: options[:type], mutable: options[:mutable], required: options[:required])
    end
    self.class.outputs.each do |name, options|
      @context.output!(name, type: options[:type])
    end
  else
    @context = Context.build(context)
    @context.action = self
  end
end