lib/attestor/validations/validators.rb in attestor-0.3.0 vs lib/attestor/validations/validators.rb in attestor-0.4.0

- old
+ new

@@ -40,36 +40,44 @@ # @param [#to_sym] context # # @return [Attestor::Validators] def set(context) validators = select { |item| item.used_in_context? context } - (validators == items) ? self : self.class.new(validators) + + self.class.new(validators) end # Returns validators updated by a new validator with given args # # @param [Array] args # # @return [Attestor::Validators] - def add_validator(*args) - add_item Validator, *args + def add_validator(*args, &block) + add_item Validator, *args, &block end - # Returns validators updated by a new follower with given args + # Returns validators updated by a new validator with given args # # @param [Array] args # # @return [Attestor::Validators] + def add_delegator(*args, &block) + add_item Delegator, *args, &block + end + + # @deprecated def add_follower(*args) + warn "[DEPRECATED] .add_follower is deprecated since v1.0.0" \ + " Use .validates method instead." add_item Follower, *args end private attr_reader :items - def add_item(type, *args) - item = type.new(*args) + def add_item(type, *args, &block) + item = type.new(*args, &block) include?(item) ? self : self.class.new(items, item) end end # class Validators