class Metaractor::Errors::Error

Attributes

object[R]
value[R]

Public Class Methods

new(value:, object: nil) click to toggle source
# File lib/metaractor/errors.rb, line 10
def initialize(value:, object: nil)
  @value = value
  @object = object
end

Public Instance Methods

==(other) click to toggle source
# File lib/metaractor/errors.rb, line 48
def ==(other)
  if other.is_a?(self.class)
    @value == other.value
  else
    @value == other
  end
end
Also aliased as: eql?
eql?(other)
Alias for: ==
generate_message(path_elements:) click to toggle source
# File lib/metaractor/errors.rb, line 15
def generate_message(path_elements:)
  if @value.is_a? Symbol
    defaults = []

    if object.class.respond_to?(:i18n_parent_names) &&
        !object.class.i18n_parent_names.empty?

      names = object.class.i18n_parent_names
      until names.empty?
        defaults << ['errors', names.join('.'), 'parameters', path_elements.join('.'), @value.to_s].reject do |item|
          item.nil? || item == ''
        end.join('.').to_sym
        names.pop
      end
    end

    unless path_elements.empty?
      defaults << :"errors.parameters.#{path_elements.join('.')}.#{@value}"
    end
    defaults << :"errors.parameters.#{@value}"

    key = defaults.shift
    I18n.translate(
      key,
      default: defaults,
      error_key: @value,
      parameter: path_elements.last
    )
  else
    "#{path_elements.join('.')} #{@value}".lstrip
  end
end
hash() click to toggle source
# File lib/metaractor/errors.rb, line 57
def hash
  @value.hash
end
inspect() click to toggle source
# File lib/metaractor/errors.rb, line 61
def inspect
  "(Error) #{@value.inspect}"
end