Class: Objecheck::Validator::RespondToRule

Inherits:
Object
  • Object
show all
Defined in:
lib/objecheck/validator/respond_to_rule.rb

Overview

RespondToRule validates methods of object

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_validator, methods) ⇒ RespondToRule

Returns a new instance of RespondToRule.



20
21
22
# File 'lib/objecheck/validator/respond_to_rule.rb', line 20

def initialize(_validator, methods)
  @methods = methods
end

Class Method Details

.schemaObject



29
30
31
# File 'lib/objecheck/validator/respond_to_rule.rb', line 29

def self.schema
  [{ each: { type: Symbol } }]
end

Instance Method Details

#validate(target, collector) ⇒ Object



24
25
26
27
# File 'lib/objecheck/validator/respond_to_rule.rb', line 24

def validate(target, collector)
  not_responds = @methods.reject { |m| target.respond_to?(m) }
  collector.add_error("should be respond to #{not_responds.join(', ')}") if !not_responds.empty?
end