Sha256: a1ada809cdc95bc7f69267b762507c1130ef78dbaca53afa08ab6a9868c36baf

Contents?: true

Size: 1015 Bytes

Versions: 6

Compression:

Stored size: 1015 Bytes

Contents

module ActionLogic
  module ActionCore
    attr_accessor :context

    def initialize(params)
      self.context = make_context(params)
    end

    def make_context(params = {})
      ActionContext.new(params)
    end

    def break?
      context.status == :failure ||
        context.status == :halted
    end

    module ClassMethods
      def around(params, &block)
        execution_context = self.new(params)

        return execution_context.context if execution_context.break?

        execution_context.set_validation_rules
        execution_context.validations!(:before)
        execution_context.validations!(:around)

        begin
          block.call(execution_context)
        rescue => e
          if execution_context.respond_to?(:error)
            execution_context.error(e)
          else
            raise e
          end
        end

        execution_context.validations!(:after)
        execution_context.validations!(:around)

        execution_context.context
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
action_logic-0.2.1 lib/action_logic/action_core.rb
action_logic-0.2.0 lib/action_logic/action_core.rb
action_logic-0.1.0 lib/action_logic/action_core.rb
action_logic-0.0.6 lib/action_logic/action_core.rb
action_logic-0.0.5 lib/action_logic/action_core.rb
action_logic-0.0.4 lib/action_logic/action_core.rb