Class: PuppetLanguageServerSidecar::FileDocumentation

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-languageserver-sidecar/puppet_strings_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ FileDocumentation

Returns a new instance of FileDocumentation.



353
354
355
356
357
358
359
# File 'lib/puppet-languageserver-sidecar/puppet_strings_helper.rb', line 353

def initialize(path = nil)
  @path      = path
  @classes   = PuppetLanguageServer::Sidecar::Protocol::PuppetClassList.new
  @datatypes = PuppetLanguageServer::Sidecar::Protocol::PuppetDataTypeList.new
  @functions = PuppetLanguageServer::Sidecar::Protocol::PuppetFunctionList.new
  @types     = PuppetLanguageServer::Sidecar::Protocol::PuppetTypeList.new
end

Instance Attribute Details

#classesObject

PuppetLanguageServer::Sidecar::Protocol::PuppetClassList object holding all classes



342
343
344
# File 'lib/puppet-languageserver-sidecar/puppet_strings_helper.rb', line 342

def classes
  @classes
end

#datatypesObject

PuppetLanguageServer::Sidecar::Protocol::PuppetDataTypeList object holding all types



345
346
347
# File 'lib/puppet-languageserver-sidecar/puppet_strings_helper.rb', line 345

def datatypes
  @datatypes
end

#functionsObject

PuppetLanguageServer::Sidecar::Protocol::PuppetFunctionList object holding all functions



348
349
350
# File 'lib/puppet-languageserver-sidecar/puppet_strings_helper.rb', line 348

def functions
  @functions
end

#pathObject

The path to file that has been documented



339
340
341
# File 'lib/puppet-languageserver-sidecar/puppet_strings_helper.rb', line 339

def path
  @path
end

#typesObject

PuppetLanguageServer::Sidecar::Protocol::PuppetTypeList object holding all types



351
352
353
# File 'lib/puppet-languageserver-sidecar/puppet_strings_helper.rb', line 351

def types
  @types
end

Instance Method Details

#from_json!(json_string) ⇒ Object

Deserialisation



377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# File 'lib/puppet-languageserver-sidecar/puppet_strings_helper.rb', line 377

def from_json!(json_string)
  obj = JSON.parse(json_string)

  obj.keys.each do |key|
    case key
    when 'path'
      # Simple deserialised object types
      self.instance_variable_set(:"@#{key}", obj[key]) # rubocop:disable Style/RedundantSelf   Reads better this way
    else
      # Sidecar protocol list object types
      prop = self.instance_variable_get(:"@#{key}") # rubocop:disable Style/RedundantSelf   Reads better this way

      obj[key].each do |child_hash|
        child = prop.child_type.new
        # Let the sidecar deserialise for us
        prop << child.from_h!(child_hash)
      end
    end
  end
  self
end

#to_hObject

Serialisation



362
363
364
365
366
367
368
369
370
# File 'lib/puppet-languageserver-sidecar/puppet_strings_helper.rb', line 362

def to_h
  {
    'path' => path,
    'classes' => classes,
    'datatypes' => datatypes,
    'functions' => functions,
    'types' => types
  }
end

#to_json(*options) ⇒ Object



372
373
374
# File 'lib/puppet-languageserver-sidecar/puppet_strings_helper.rb', line 372

def to_json(*options)
  JSON.generate(to_h, options)
end