Class: LogStash::Config::AST::Hash

Inherits:
Value
  • Object
show all
Defined in:
lib/logstash/config/config_ast.rb

Instance Method Summary collapse

Methods inherited from Node

#text_value_for_comments

Instance Method Details

#compileObject



400
401
402
403
# File 'lib/logstash/config/config_ast.rb', line 400

def compile
  validate!
  return "{" << recursive_select(HashEntry).collect(&:compile).reject(&:empty?).join(", ") << "}"
end

#find_duplicate_keysObject



395
396
397
398
# File 'lib/logstash/config/config_ast.rb', line 395

def find_duplicate_keys
  values = recursive_select(HashEntry).collect { |hash_entry| hash_entry.name.text_value }
  values.find_all { |v| values.count(v) > 1 }.uniq
end

#validate!Object



379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/logstash/config/config_ast.rb', line 379

def validate!
  duplicate_values = find_duplicate_keys

  if duplicate_values.size > 0
    raise ConfigurationError.new(
      I18n.t("logstash.runner.configuration.invalid_plugin_settings_duplicate_keys",
             :keys => duplicate_values.join(', '),
             :line => input.line_of(interval.first),
             :column => input.column_of(interval.first),
             :byte => interval.first + 1,
             :after => input[0..interval.first]
            )
    )
  end
end