Class: JsonLint::Linter::KeyOverlapDetector

Inherits:
Oj::Saj
  • Object
show all
Defined in:
lib/jsonlint/linter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeKeyOverlapDetector

Returns a new instance of KeyOverlapDetector.



92
93
94
95
96
97
98
99
# File 'lib/jsonlint/linter.rb', line 92

def initialize
  @seen_keys = Set.new
  @key_components = []
  @overlapping_keys = Set.new

  @complex_type = []
  @array_positions = []
end

Instance Attribute Details

#overlapping_keysObject (readonly)

Returns the value of attribute overlapping_keys.



90
91
92
# File 'lib/jsonlint/linter.rb', line 90

def overlapping_keys
  @overlapping_keys
end

Instance Method Details

#add_value(value, key) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/jsonlint/linter.rb', line 145

def add_value(value, key)
  JsonLint.logger.debug { "add_value: #{value.inspect}, #{key.inspect}" }
  case @complex_type.last
  when :hash
    @key_components.push(key)
    check_for_overlap!
    @key_components.pop
  when :array
    @key_components.push(@array_positions.last)
    check_for_overlap!
    @array_positions[-1] += 1
    @key_components.pop
  end
end

#array_end(key) ⇒ Object



138
139
140
141
142
143
# File 'lib/jsonlint/linter.rb', line 138

def array_end(key)
  JsonLint.logger.debug { "array_end: #{key.inspect}" }
  @key_components.pop
  @complex_type.pop
  @array_positions.pop
end

#array_start(key) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/jsonlint/linter.rb', line 122

def array_start(key)
  JsonLint.logger.debug { "array_start: #{key.inspect}" }

  case @complex_type.last
  when :hash
    @key_components.push(key)
  when :array
    @key_components.push(@array_positions.last)
    @array_positions[-1] += 1
  end

  @complex_type.push(:array)
  @array_positions.push(0)
  check_for_overlap!
end

#error(message, line, column) ⇒ Object



160
161
162
# File 'lib/jsonlint/linter.rb', line 160

def error(message, line, column)
  JsonLint.logger.debug { "error: #{message.inspect}, #{line.inspect}, #{column.inspect}" }
end

#hash_end(key) ⇒ Object



116
117
118
119
120
# File 'lib/jsonlint/linter.rb', line 116

def hash_end(key)
  JsonLint.logger.debug { "hash_end: #{key.inspect}" }
  @key_components.pop
  @complex_type.pop
end

#hash_start(key) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/jsonlint/linter.rb', line 101

def hash_start(key)
  JsonLint.logger.debug { "hash_start: #{key.inspect}" }

  case @complex_type.last
  when :hash
    @key_components.push(key)
  when :array
    @key_components.push(@array_positions.last)
    @array_positions[-1] += 1
  end

  @complex_type.push(:hash)
  check_for_overlap!
end