Sha256: e0cbf56e424daf63d257364071d28602803451e5c2fcdca2de849054042ab176
Contents?: true
Size: 1.01 KB
Versions: 3
Compression:
Stored size: 1.01 KB
Contents
# frozen_string_literal: true require 'active_support/concern' module ActForm class RunError < StandardError; end # Define runnable behaivor for form object. module Runnable extend ActiveSupport::Concern included do attr_reader :result end class_methods do def setup(&block) self.before_validation(&block) end def run(*args) new(*args).run end def run!(*args) new(*args).run! end end def has_errors? # rubocop:disable Naming/PredicateName !errors.empty? end def run if valid? @result = perform @performed = true end self end def run! if valid? # rubocop:disable Style/GuardClause @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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
act_form-0.5.0 | lib/act_form/runnable.rb |
act_form-0.4.4 | lib/act_form/runnable.rb |
act_form-0.4.3 | lib/act_form/runnable.rb |