Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(maint) Refactor in-memory cache objects #140

Merged
merged 1 commit into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 14 additions & 51 deletions lib/puppet-languageserver/puppet_helper/cache_objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,31 @@

module PuppetLanguageServer
module PuppetHelper
# key => Unique name of the object
# calling_source => The file that was invoked to create the object
# source => The file that _actually_ created the object
# line => The line number in the source file where the object was created
# char => The character number in the source file where the object was created
# length => The length of characters from `char` in the source file where the object was created
class BasePuppetObject
attr_accessor :key
attr_accessor :calling_source
attr_accessor :source
attr_accessor :line
attr_accessor :char
attr_accessor :length
module CacheExtensions
# origin is used to store where this cache entry came from, for example, workspace or
# default environment
attr_accessor :origin

def from_sidecar!(value)
@key = value.key
@calling_source = value.calling_source
@source = value.source
@line = value.line
@char = value.char
@length = value.length
(value.class.instance_methods - Object.instance_methods).reject { |name| name.to_s.end_with?('=') || name.to_s.end_with?('!') }
.reject { |name| %i[to_h to_json].include?(name) }
.each do |method_name|
send("#{method_name}=", value.send(method_name))
end
self
end
end

class PuppetClass < BasePuppetObject
attr_accessor :doc
attr_accessor :parameters

def from_sidecar!(value)
super
@doc = value.doc
@parameters = value.parameters
self
end
class PuppetClass < PuppetLanguageServer::Sidecar::Protocol::PuppetClass
include CacheExtensions
end

class PuppetFunction < BasePuppetObject
attr_accessor :doc
attr_accessor :arity
attr_accessor :type

def from_sidecar!(value)
super
@doc = value.doc
@arity = value.arity
@type = value.type
self
end
class PuppetFunction < PuppetLanguageServer::Sidecar::Protocol::PuppetFunction
include CacheExtensions
end

class PuppetType < BasePuppetObject
attr_accessor :doc
attr_accessor :attributes
class PuppetType < PuppetLanguageServer::Sidecar::Protocol::PuppetType
include CacheExtensions

def allattrs
@attributes.keys
Expand All @@ -73,13 +43,6 @@ def properties
def meta_parameters
@attributes.select { |_name, data| data[:type] == :meta }
end

def from_sidecar!(value)
super
@doc = value.doc
@attributes = value.attributes
self
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
it_should_behave_like 'a base Puppet object'

# No additional methods to test
# [:doc].each do |testcase|
# it "instance should respond to #{testcase}" do
# expect(subject).to respond_to(testcase)
# end
# end
[:doc, :parameters].each do |testcase|
it "instance should respond to #{testcase}" do
expect(subject).to respond_to(testcase)
end
end

describe '#from_sidecar!' do
it 'should populate from a sidecar function object' do
Expand Down