Class: Rwm::VscodeWorkspace

Inherits:
Object
  • Object
show all
Defined in:
lib/rwm/vscode_workspace.rb

Constant Summary collapse

PRESERVE_KEYS =
%w[settings extensions launch tasks].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ VscodeWorkspace



11
12
13
# File 'lib/rwm/vscode_workspace.rb', line 11

def initialize(root)
  @root = root
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



9
10
11
# File 'lib/rwm/vscode_workspace.rb', line 9

def root
  @root
end

Instance Method Details

#file_pathObject



15
16
17
# File 'lib/rwm/vscode_workspace.rb', line 15

def file_path
  File.join(root, "#{File.basename(root)}.code-workspace")
end

#generate(packages) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rwm/vscode_workspace.rb', line 19

def generate(packages)
  existing = load_existing
  folders = build_folders(packages)

  data = { "folders" => folders }

  PRESERVE_KEYS.each do |key|
    data[key] = existing[key] if existing.key?(key)
  end

  data["settings"] ||= {}

  File.write(file_path, JSON.pretty_generate(data) + "\n")
end