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.



87
88
89
90
91
92
93
94
# File 'lib/jsonlint/linter.rb', line 87

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.



85
86
87
# File 'lib/jsonlint/linter.rb', line 85

def overlapping_keys
  @overlapping_keys
end

Instance Method Details

#add_value(value, key) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/jsonlint/linter.rb', line 140

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



133
134
135
136
137
138
# File 'lib/jsonlint/linter.rb', line 133

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



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/jsonlint/linter.rb', line 117

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



155
156
157
# File 'lib/jsonlint/linter.rb', line 155

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

#hash_end(key) ⇒ Object



111
112
113
114
115
# File 'lib/jsonlint/linter.rb', line 111

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

#hash_start(key) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/jsonlint/linter.rb', line 96

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