Class: StrongJSON::Type::ErrorPath

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, parent:) ⇒ ErrorPath

Returns a new instance of ErrorPath.



414
415
416
417
# File 'lib/strong_json/type.rb', line 414

def initialize(type:, parent:)
  @type = type
  @parent = parent
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



412
413
414
# File 'lib/strong_json/type.rb', line 412

def parent
  @parent
end

#typeObject (readonly)

Returns the value of attribute type.



412
413
414
# File 'lib/strong_json/type.rb', line 412

def type
  @type
end

Class Method Details

.root(type) ⇒ Object



431
432
433
# File 'lib/strong_json/type.rb', line 431

def self.root(type)
  self.new(type: type, parent: nil)
end

Instance Method Details

#dig(key:, type:) ⇒ Object



419
420
421
422
423
# File 'lib/strong_json/type.rb', line 419

def dig(key:, type:)
  # @type var parent: [Integer | Symbol | nil, ErrorPath]
  parent = [key, self]
  self.class.new(type: type, parent: parent)
end

#expand(type:) ⇒ Object



425
426
427
428
429
# File 'lib/strong_json/type.rb', line 425

def expand(type:)
  # @type var parent: [Integer | Symbol | nil, ErrorPath]
  parent = [nil, self]
  self.class.new(type: type, parent: parent)
end

#root?Boolean

Returns:

  • (Boolean)


435
436
437
# File 'lib/strong_json/type.rb', line 435

def root?
  !parent
end

#to_sObject



439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
# File 'lib/strong_json/type.rb', line 439

def to_s
  if pa = parent
    if key = pa[0]
      pa[1].to_s + case key
                   when Integer
                     "[#{key}]"
                   when Symbol
                     ".#{key}"
                   end
    else
      pa[1].to_s
    end
  else
    "$"
  end
end