Class: RemoteSh::WorkspaceConfiguration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/remote_sh/workspace_configuration.rb

Constant Summary collapse

WOKRING_DIR =
Dir.pwd
CONFIGURATION_FILE =
"#{WOKRING_DIR}/.remote_sh/connection.yaml"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configObject

host: name_from_config host_path: path_on_server ignore: …



16
17
18
# File 'lib/remote_sh/workspace_configuration.rb', line 16

def self.config
  instance.config
end

.host_configObject



20
21
22
# File 'lib/remote_sh/workspace_configuration.rb', line 20

def self.host_config
  instance.host_config
end

.init!Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/remote_sh/workspace_configuration.rb', line 24

def self.init!
  current_path = Dir.getwd

  default_server = HostsConfiguration.config['default_server']
  default_remote_root_path = HostsConfiguration.config['default_remote_root_path']
  default_local_root_path = HostsConfiguration.config['default_local_root_path']

  Dir.mkdir("#{current_path}/.remote_sh")

  current_relative_path = current_path.delete_prefix(default_local_root_path)

  remote_path = "#{default_remote_root_path}#{current_relative_path}"
  host = HostsConfiguration.config['servers'].find { |s| s['name'] == default_server }['host']

  `ssh #{host} "mkdir -p #{remote_path}"`

  File.open("#{Dir.getwd}/.remote_sh/connection.yaml", 'w') do |file|
    file.write(<<~YAML)
      host: main
      host_path: #{remote_path}
      ignore:
        - .gitignore
    YAML
  end
end

Instance Method Details

#configObject



54
55
56
# File 'lib/remote_sh/workspace_configuration.rb', line 54

def config
  @config || parse
end

#host_configObject



58
59
60
61
# File 'lib/remote_sh/workspace_configuration.rb', line 58

def host_config
  @host_config ||=
    HostsConfiguration.config["servers"].find { _1["name"] == config["host"] }
end

#parseObject



50
51
52
# File 'lib/remote_sh/workspace_configuration.rb', line 50

def parse
  @config = YAML.load_file(CONFIGURATION_FILE)
end