Class: Shippy::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/shippy/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Config

Returns a new instance of Config.



5
6
7
8
# File 'lib/shippy/config.rb', line 5

def initialize(file)
  @data = YAML.load_file(file).deep_symbolize_keys
  @secrets = Secrets.new(@data.fetch(:secrets_file) { "config/secrets.yml.enc" })
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/shippy/config.rb', line 48

def method_missing(name, *args)
  if data.key?(name)
    data.fetch(name)
  else
    super
  end
end

Instance Attribute Details

#data ⇒ Object (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/shippy/config.rb', line 3

def data
  @data
end

Instance Method Details

#bind_volume_path(name) ⇒ Object



14
15
16
# File 'lib/shippy/config.rb', line 14

def bind_volume_path(name)
  File.join(deploy_path, "volumes", name)
end

#deploy_path ⇒ Object



44
45
46
# File 'lib/shippy/config.rb', line 44

def deploy_path
  Pathname.new(deploy_to)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/shippy/config.rb', line 56

def respond_to_missing?(name, include_private = false)
  data.key?(name) || super
end

#secrets(app, name) ⇒ Object



10
11
12
# File 'lib/shippy/config.rb', line 10

def secrets(app, name)
  @secrets.fetch(app, name)
end

#ssh_keys ⇒ Object



37
38
39
40
41
42
# File 'lib/shippy/config.rb', line 37

def ssh_keys
  keys = data.dig(:ssh, :keys)
  return if keys.nil?

  Array(keys).map { |k| File.expand_path(k) }
end

#ssh_options ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/shippy/config.rb', line 18

def ssh_options
  options = {
    user: ssh_user,
    port: ssh_port,
    keys: ssh_keys,
    auth_methods: ["publickey"]
  }

  options.compact
end

#ssh_port ⇒ Object



33
34
35
# File 'lib/shippy/config.rb', line 33

def ssh_port
  data.dig(:ssh, :port)
end

#ssh_user ⇒ Object



29
30
31
# File 'lib/shippy/config.rb', line 29

def ssh_user
  data.dig(:ssh, :user) || "root"
end