Class: PuppetLanguageServer::Sidecar::Protocol::AggregateMetadata

Inherits:
BaseClass
  • Object
show all
Defined in:
lib/puppet-languageserver/sidecar_protocol.rb

Overview

This class is a little special as it contains a lot logic. In essence this is just wrapping a hash with specific methods for the the different types of metadata (classes, functions etc.)

Instance Method Summary collapse

Methods inherited from BaseClass

#==, #eql?, #hash

Constructor Details

#initializeAggregateMetadata

Returns a new instance of AggregateMetadata.



419
420
421
422
# File 'lib/puppet-languageserver/sidecar_protocol.rb', line 419

def initialize
  super
  @aggregate = {}
end

Instance Method Details

#append!(obj) ⇒ Object



446
447
448
# File 'lib/puppet-languageserver/sidecar_protocol.rb', line 446

def append!(obj)
  list_for_object_class(obj.class) << obj
end

#classesObject



424
425
426
# File 'lib/puppet-languageserver/sidecar_protocol.rb', line 424

def classes
  @aggregate[:classes]
end

#concat!(array) ⇒ Object



440
441
442
443
444
# File 'lib/puppet-languageserver/sidecar_protocol.rb', line 440

def concat!(array)
  return if array.nil? || array.empty?

  array.each { |item| append!(item) }
end

#datatypesObject



428
429
430
# File 'lib/puppet-languageserver/sidecar_protocol.rb', line 428

def datatypes
  @aggregate[:datatypes]
end

#each_list(&block) ⇒ Object



466
467
468
469
470
# File 'lib/puppet-languageserver/sidecar_protocol.rb', line 466

def each_list(&block)
  return unless block

  @aggregate.each(&block)
end

#from_json!(json_string) ⇒ Object



454
455
456
457
458
459
460
461
462
463
464
# File 'lib/puppet-languageserver/sidecar_protocol.rb', line 454

def from_json!(json_string)
  obj = ::JSON.parse(json_string)
  obj.each do |key, value|
    info = METADATA_LIST[key.intern]
    next if info.nil?

    list = list_for_object_class(info[:item_class])
    value.each { |i| list << info[:item_class].new.from_h!(i) }
  end
  self
end

#functionsObject



432
433
434
# File 'lib/puppet-languageserver/sidecar_protocol.rb', line 432

def functions
  @aggregate[:functions]
end

#to_json(*options) ⇒ Object



450
451
452
# File 'lib/puppet-languageserver/sidecar_protocol.rb', line 450

def to_json(*options)
  @aggregate.to_json(options)
end

#typesObject



436
437
438
# File 'lib/puppet-languageserver/sidecar_protocol.rb', line 436

def types
  @aggregate[:types]
end