Module: StoreModel::CombineErrorsStrategies

Defined in:
lib/store_model/combine_errors_strategies.rb,
lib/store_model/combine_errors_strategies/merge_error_strategy.rb,
lib/store_model/combine_errors_strategies/mark_invalid_error_strategy.rb

Overview

Module with built-in strategies for combining errors.

Defined Under Namespace

Classes: MarkInvalidErrorStrategy, MergeErrorStrategy

Class Method Summary collapse

Class Method Details

.configure(options) ⇒ Object

Finds a strategy based on options and global config.

Parameters:

  • options (Hash)

Returns:

  • (Object)

    strategy



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/store_model/combine_errors_strategies.rb', line 16

def configure(options)
  configured_strategy = options[:merge_errors] || StoreModel.config.merge_errors

  if configured_strategy.respond_to?(:call)
    configured_strategy
  elsif configured_strategy == true
    StoreModel::CombineErrorsStrategies::MergeErrorStrategy.new
  elsif configured_strategy.nil?
    StoreModel::CombineErrorsStrategies::MarkInvalidErrorStrategy.new
  else
    const_get(configured_strategy.to_s.camelize).new
  end
end