Class: StructuredReader::JSONReader::ValidatorContext

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

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(where = "", errors = []) ⇒ ValidatorContext

Returns a new instance of ValidatorContext.



353
354
355
356
# File 'lib/structured_reader.rb', line 353

def initialize(where = "", errors = [])
  @where = where.dup.freeze
  @errors = errors
end

Instance Method Details

#accept(fragment) ⇒ Object



363
364
365
# File 'lib/structured_reader.rb', line 363

def accept(fragment)
  fragment
end

#flunk(fragment, reason) ⇒ Object



367
368
369
# File 'lib/structured_reader.rb', line 367

def flunk(fragment, reason)
  @errors << [@where, reason]
end

#open(&blk) ⇒ Object



358
359
360
361
# File 'lib/structured_reader.rb', line 358

def open(&blk)
  result = blk.call(self)
  Result.new(@errors.any? ? nil : result, @errors)
end

#push(path) {|self.class.new(@where + path, @errors)| ... } ⇒ Object

Yields:

  • (self.class.new(@where + path, @errors))


371
372
373
# File 'lib/structured_reader.rb', line 371

def push(path)
  yield self.class.new(@where + path, @errors)
end