Class: Inspector::Validator

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

Instance Method Summary collapse

Constructor Details

#initialize(metadata_map, walker, type_metadata_class) ⇒ Validator

Returns a new instance of Validator.



3
4
5
6
7
# File 'lib/inspector/validator.rb', line 3

def initialize(, walker, )
  @metadata_map = 
  @walker = walker
  @type_metadata_class = 
end

Instance Method Details

#valid(type, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/inspector/validator.rb', line 9

def valid(type, &block)
   = @type_metadata_class.new(type)
  if block_given?
    block.arity == 1 ? yield() : .instance_eval(&block)
  end
  @metadata_map[type] = 

  nil
end

#validate(object, opts = {}) ⇒ Object



19
20
21
22
23
24
# File 'lib/inspector/validator.rb', line 19

def validate(object, opts = {})
  type       = opts.fetch(:as) { object.class }
     = @metadata_map[type]

  @walker.walk_object(, object)
end