Class: ORS::Config

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

Constant Summary collapse

CONFIG_FILENAME =
"config/deploy.yml"
@@args =
[]
@@options =
{}

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Config

Returns a new instance of Config.



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

def initialize(options)
  parse_options(options)
  parse_config_file
end

Instance Method Details

#[](key) ⇒ Object



18
19
20
# File 'lib/ors/config.rb', line 18

def [](key)
  @@options[key]
end

#[]=(key, value) ⇒ Object



22
23
24
# File 'lib/ors/config.rb', line 22

def []=(key, value)
  @@options[key] = value
end

#_optionsObject



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

def _options
  @@options
end

#finalize!Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/ors/config.rb', line 72

def finalize!
  @@options[:name] = name
  @@options[:remote_url] = remote_url
  @@options[:deploy_directory] = deploy_directory

  @@options[:revision] = git.log(1).first.sha

  @@options[:ruby_servers] = [@@options[:app_servers], @@options[:console_server], @@options[:cron_server], @@options[:migration_server]].flatten.compact.uniq
  @@options[:all_servers] = [@@options[:web_servers], @@options[:ruby_servers]].flatten.compact.uniq
end

#gitObject



83
84
85
# File 'lib/ors/config.rb', line 83

def git
  @git ||= Git.open(Dir.pwd)
end

#parse_config_fileObject



64
65
66
67
68
69
70
# File 'lib/ors/config.rb', line 64

def parse_config_file
  if File.exists?(CONFIG_FILENAME)
    YAML.load(File.read(CONFIG_FILENAME)).each do |(name, value)|
      @@options[name.to_sym] = value
    end
  end
end

#parse_options(options) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ors/config.rb', line 26

def parse_options(options)
  @@options[:pretending] = true if options.delete("-p") || options.delete("--pretend")

  if options.delete("-ng") || options.delete("--no-gateway")
    @@options[:use_gateway] = false
  else
    @@options[:use_gateway] = true
  end

  # grab environment
  index = options.index("to") || options.index("from")
  unless index.nil?
    @@options[:environment] = options.delete_at(index + 1)
    options.delete_at(index)
  end

  @@options[:args] = options.dup

  set_default_options
end

#set_default_optionsObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ors/config.rb', line 47

def set_default_options
  @@options[:environment]    ||= "production"
  @@options[:remote]         ||= "origin"
  @@options[:branch]         ||= @@options[:environment]
  @@options[:pretending]     ||= false
  @@options[:log_lines]        = 100

  @@options[:gateway]          = "deploy-gateway"
  @@options[:user]             = "deployer"
  @@options[:base_path]        = "/var/www"
  @@options[:web_servers]      = %w(koala)
  @@options[:app_servers]      = %w(eel jellyfish squid)
  @@options[:migration_server] = "tuna"
  @@options[:console_server]   = "tuna"
  @@options[:cron_server]      = "tuna"
end

#valid?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/ors/config.rb', line 87

def valid?
  name.to_s.size > 0
end