Sha256: a1e0628c5a06d66c897186b55958012385bdca1df7777a526ed650dde56aca85

Contents?: true

Size: 804 Bytes

Versions: 5

Compression:

Stored size: 804 Bytes

Contents

require 'active_support/concern'

module ActForm
  class RunError < StandardError; end
  module Runnable
    extend ActiveSupport::Concern

    included do
      attr_reader :result
    end

    class_methods do
      def run(*args)
        new(*args).run
      end

      def run!(*args)
        new(*args).run!
      end
    end

    def has_errors?
      !errors.empty?
    end

    def run
      if valid?
        @result    = perform
        @performed = true
      end
      self
    end

    def run!
      if valid?
        @result    = perform
        @performed = true
        result
      else
        raise RunError, 'Verification failed'
      end
    end

    def perform; end

    def success?
      !has_errors? && !!@performed
    end

    def failure?
      !success?
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
act_form-0.4.1 lib/act_form/runnable.rb
act_form-0.4.0 lib/act_form/runnable.rb
act_form-0.3.2 lib/act_form/runnable.rb
act_form-0.3.1 lib/act_form/runnable.rb
act_form-0.3.0 lib/act_form/runnable.rb