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))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/shippy/config.rb', line 30

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

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

Instance Method Details

#deploy_pathObject



26
27
28
# File 'lib/shippy/config.rb', line 26

def deploy_path
  Pathname.new(deploy_to)
end

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

Returns:

  • (Boolean)


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

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_optionsObject



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

def ssh_options
  {user: ssh_user, auth_methods: ["publickey"]}.compact
end

#ssh_userObject



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

def ssh_user
  if data[:ssh].present?
    data.dig(:ssh, :user) || "root"
  else
    "root"
  end
end