Sha256: 93793d51156117876c343bc3736e2b3744829480c2e14595a61c0619d8e64803

Contents?: true

Size: 1.11 KB

Versions: 11

Compression:

Stored size: 1.11 KB

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)
        with_benchmark(self) do
          execute!(params, &block)
        end
      end

      def execute!(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

11 entries across 11 versions & 1 rubygems

Version Path
action_logic-0.3.3 lib/action_logic/action_core.rb
action_logic-0.3.2 lib/action_logic/action_core.rb
action_logic-0.3.1 lib/action_logic/action_core.rb
action_logic-0.3.0 lib/action_logic/action_core.rb
action_logic-0.2.8 lib/action_logic/action_core.rb
action_logic-0.2.7 lib/action_logic/action_core.rb
action_logic-0.2.6 lib/action_logic/action_core.rb
action_logic-0.2.5 lib/action_logic/action_core.rb
action_logic-0.2.4 lib/action_logic/action_core.rb
action_logic-0.2.3 lib/action_logic/action_core.rb
action_logic-0.2.2 lib/action_logic/action_core.rb