Module: Resulting

Defined in:
lib/resulting.rb,
lib/resulting/result.rb,
lib/resulting/runner.rb,
lib/resulting/handler.rb,
lib/resulting/helpers.rb,
lib/resulting/version.rb,
lib/resulting/resultable.rb

Defined Under Namespace

Modules: Handler, Helpers, Resultable, Runner Classes: Result

Constant Summary collapse

VERSION =
"0.1.1".freeze

Class Method Summary collapse

Class Method Details

.save(result_or_value, &blk) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/resulting.rb', line 14

def save(result_or_value, &blk)
  params = { method: :save }

  if defined?(ActiveRecord::Base) && defined?(ActiveRecord::Rollback)
    params[:failure_case] = -> { raise ActiveRecord::Rollback }
    params[:wrapper] = ActiveRecord::Base.method(:transaction)
  end

  Resulting::Runner.run_until_failure(result_or_value, params, &blk)
end

.validate(result_or_value, &blk) ⇒ Object



10
11
12
# File 'lib/resulting.rb', line 10

def validate(result_or_value, &blk)
  Resulting::Runner.run_all(result_or_value, method: :validate, &blk)
end

.validate_and_save(result_or_value) ⇒ Object



25
26
27
# File 'lib/resulting.rb', line 25

def validate_and_save(result_or_value)
  save(validate(result_or_value))
end