Class: DevContext::ShellSetup

Inherits:
Object
  • Object
show all
Defined in:
lib/dev_context/shell_setup.rb

Constant Summary collapse

DEFAULT_PATH =
File.expand_path("~/.dx.sh").freeze
MANAGED_MARKER =
"DevContext shell integration generated by `dx init`".freeze
VERSION_MARKER_PREFIX =
"DX Shell Version:".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: ENV.fetch("DX_SHELL_PATH", DEFAULT_PATH)) ⇒ ShellSetup

Returns a new instance of ShellSetup.



11
12
13
# File 'lib/dev_context/shell_setup.rb', line 11

def initialize(path: ENV.fetch("DX_SHELL_PATH", DEFAULT_PATH))
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/dev_context/shell_setup.rb', line 9

def path
  @path
end

Instance Method Details

#install!Object

Returns :created, :updated, or :unchanged.



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dev_context/shell_setup.rb', line 16

def install!
  unless File.exist?(path)
    File.write(path, shell_script)
    return :created
  end

  current = File.read(path)
  return :unchanged if current == shell_script
  return :unchanged unless managed_file?(current)

  File.write(path, shell_script)
  :updated
end