Sha256: 4046f5925fc7c5427ef6caaa6df2310a8ada612bc19f8f6ab9fbf9fcfe788225

Contents?: true

Size: 534 Bytes

Versions: 2

Compression:

Stored size: 534 Bytes

Contents

require 'active_support/concern'

module ActForm
  module Runnable
    extend ActiveSupport::Concern

    included do
      attr_reader :result
    end

    class_methods do
      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 perform; end

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

    def failure?
      !success?
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
act_form-0.2.0 lib/act_form/runnable.rb
act_form-0.1.0 lib/act_form/runnable.rb