lib/tram/policy/errors.rb in tram-policy-0.2.0 vs lib/tram/policy/errors.rb in tram-policy-0.2.1
- old
+ new
@@ -12,10 +12,11 @@
#
# @return [Tram::Policy] the poplicy errors provided by
#
attr_reader :policy
+ # @!method add(message, tags)
# Adds error message to the collection
#
# @param [#to_s] message Either a message, or a symbolic key for translation
# @param [Hash<Symbol, Object>] tags Tags to be attached to the message
# @return [self] the collection
@@ -35,20 +36,22 @@
#
def each
@set.each { |error| yield(error) }
end
+ # @!method by_tags(filter)
# Selects errors filtered by tags
#
- # @param [Hash<Symbol, Object>] filter
+ # @param [Hash<Symbol, Object>] filter List of options to filter by
# @return [Hash<Symbol, Object>]
#
def by_tags(**filter)
filter = filter.to_a
reject { |error| (filter - error.to_h.to_a).any? }
end
+ # @!method empty?
# Checks whether a collection is empty
#
# @return [Boolean]
#
def empty?(&block)
@@ -69,14 +72,17 @@
#
def full_messages
@set.map(&:full_message).sort
end
+ # @!method merge(other, options)
# Merges other collection to the current one and returns new collection
# with the current scope
#
- # param [Tram::Policy::Errors] other Collection to be merged
- # yieldparam [Hash<Symbol, Object>]
+ # @param [Tram::Policy::Errors] other Collection to be merged
+ # @param [Hash<Symbol, Object>] options Options to be added to merged errors
+ # @yieldparam [Hash<Symbol, Object>] hash of error options
+ # @return [self]
#
# @example Add some tag to merged errors
# policy.merge(other) { |err| err[:source] = "other" }
#
def merge(other, **options)