lib/tram/policy/error.rb in tram-policy-1.0.1 vs lib/tram/policy/error.rb in tram-policy-2.0.0

- old
+ new

@@ -10,14 +10,14 @@ # Builds an error # # If another error is send to the constructor, the error returned unchanged # # @param [Tram::Policy::Error, #to_s] value - # @param [Hash<Symbol, Object>] opts + # @param [Hash<Symbol, Object>] tags # @return [Tram::Policy::Error] # - def self.new(value, **opts) + def self.new(value, **tags) value.instance_of?(self) ? value : super end # @!attribute [r] key # @return [Symbol, String] error key @@ -25,20 +25,20 @@ # @!attribute [r] tags # @return [Hash<Symbol, Object>] error tags attr_reader :tags - # The list of arguments for [I18n.t] + # List of arguments for [I18n.t] # # @return [Array] # def item [key, tags] end alias to_a item - # The text of error message translated to the current locale + # Text of error message translated to the current locale # # @return [String] # def message key.is_a?(Symbol) ? I18n.t(*item) : key.to_s @@ -58,12 +58,12 @@ # @param [#to_sym] tag # @param [Object] default # @param [Proc] block # @return [Object] # - def fetch(tag, default = Dry::Initializer::UNDEFINED, &block) - if default == Dry::Initializer::UNDEFINED + def fetch(tag, default = UNDEFINED, &block) + if default == UNDEFINED tags.fetch(tag.to_sym, &block) else tags.fetch(tag.to_sym, default, &block) end end @@ -90,12 +90,16 @@ true end private + UNDEFINED = Dry::Initializer::UNDEFINED + DEFAULT_SCOPE = %w[tram-policy errors].freeze + def initialize(key, **tags) @key = key @tags = tags + @tags[:scope] = @tags.fetch(:scope) { DEFAULT_SCOPE } if key.is_a?(Symbol) end def respond_to_missing?(*) true end