Class: WhiskeyDisk::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/whiskey_disk/config.rb,
lib/whiskey_disk/config/filter.rb,
lib/whiskey_disk/config/abstract_filter.rb,
lib/whiskey_disk/config/filters/modules/scope_helper.rb,
lib/whiskey_disk/config/filters/project_scope_filter.rb,
lib/whiskey_disk/config/filters/default_domain_filter.rb,
lib/whiskey_disk/config/filters/add_project_name_filter.rb,
lib/whiskey_disk/config/filters/localize_domains_filter.rb,
lib/whiskey_disk/config/filters/environment_scope_filter.rb,
lib/whiskey_disk/config/filters/stringify_hash_keys_filter.rb,
lib/whiskey_disk/config/filters/add_environment_name_filter.rb,
lib/whiskey_disk/config/filters/default_config_target_filter.rb,
lib/whiskey_disk/config/filters/normalize_ssh_options_filter.rb,
lib/whiskey_disk/config/filters/hashify_domain_entries_filter.rb,
lib/whiskey_disk/config/filters/drop_empty_domain_roles_filter.rb,
lib/whiskey_disk/config/filters/check_for_duplicate_domains_filter.rb,
lib/whiskey_disk/config/filters/convert_role_strings_to_list_filter.rb,
lib/whiskey_disk/config/filters/select_project_and_environment_filter.rb

Defined Under Namespace

Modules: ScopeHelper Classes: AbstractFilter, AddEnvironmentNameFilter, AddProjectNameFilter, CheckForDuplicateDomainsFilter, ConvertRoleStringsToListFilter, DefaultConfigTargetFilter, DefaultDomainFilter, DropEmptyDomainRolesFilter, EnvironmentScopeFilter, Filter, HashifyDomainEntriesFilter, LocalizeDomainsFilter, NormalizeSshOptionsFilter, ProjectScopeFilter, SelectProjectAndEnvironmentFilter, StringifyHashKeysFilter

Instance Method Summary collapse

Instance Method Details

#base_pathObject


73
74
75
# File 'lib/whiskey_disk/config.rb', line 73

def base_path
  path || find_rakefile_from_current_path
end

#check_staleness?Boolean

Returns:

  • (Boolean)

21
22
23
# File 'lib/whiskey_disk/config.rb', line 21

def check_staleness?
  env_flag_is_true?('check')
end

#configuration_dataObject

called only by #load_data


89
90
91
# File 'lib/whiskey_disk/config.rb', line 89

def configuration_data
  open(configuration_file) {|f| f.read }
end

#configuration_fileObject


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

def configuration_file
  return path if valid_path?(path)
  
  files = []

  files += [
    File.join(base_path, 'deploy', specified_project_name, "#{environment_name}.yml"),  # /deploy/foo/staging.yml
    File.join(base_path, 'deploy', "#{specified_project_name}.yml") # /deploy/foo.yml
  ] if specified_project_name

  files += [
    File.join(base_path, 'deploy', "#{environment_name}.yml"),  # /deploy/staging.yml
    File.join(base_path, "#{environment_name}.yml"), # /staging.yml
    File.join(base_path, 'deploy.yml') # /deploy.yml
  ]

  files.each { |file|  return file if File.exists?(file) }

  raise "Could not locate configuration file in path [#{base_path}]"
end

#contains_rakefile?(path) ⇒ Boolean

Returns:

  • (Boolean)

58
59
60
# File 'lib/whiskey_disk/config.rb', line 58

def contains_rakefile?(path)
  File.exists?(File.expand_path(File.join(path, 'Rakefile')))
end

#debug?Boolean

Returns:

  • (Boolean)

13
14
15
# File 'lib/whiskey_disk/config.rb', line 13

def debug?
  env_flag_is_true?('debug')
end

#domain_limitObject


17
18
19
# File 'lib/whiskey_disk/config.rb', line 17

def domain_limit
  env_key_or_false?('only')
end

#environment_nameObject


46
47
48
49
50
# File 'lib/whiskey_disk/config.rb', line 46

def environment_name
  return false unless env_has_key?('to')
  return ENV['to'] unless ENV['to'] =~ /:/
  ENV['to'].split(/:/)[1]
end

#fetchObject


8
9
10
11
# File 'lib/whiskey_disk/config.rb', line 8

def fetch
  raise "Cannot determine current environment -- try rake ... to=staging, for example." unless environment_name
  filter_data(load_data)
end

#filterObject


100
101
102
# File 'lib/whiskey_disk/config.rb', line 100

def filter
  @filter ||= WhiskeyDisk::Config::Filter.new(self)
end

#filter_data(data) ⇒ Object

called only by #fetch


105
106
107
# File 'lib/whiskey_disk/config.rb', line 105

def filter_data(data)
  filter.filter_data(data)
end

#find_rakefile_from_current_pathObject


62
63
64
65
66
67
68
69
70
71
# File 'lib/whiskey_disk/config.rb', line 62

def find_rakefile_from_current_path
  original_path = Dir.pwd
  while (!contains_rakefile?(Dir.pwd))
    return File.join(original_path, 'config') if Dir.pwd == '/'
    Dir.chdir('..')
  end
  File.join(Dir.pwd, 'config')
ensure
  Dir.chdir(original_path)
end

#load_dataObject

called only by #fetch


94
95
96
97
98
# File 'lib/whiskey_disk/config.rb', line 94

def load_data
  YAML.load(configuration_data)
rescue Exception => e
  raise %Q{Error reading configuration file [#{configuration_file}]: "#{e}"}
end

#project_nameObject


84
85
86
# File 'lib/whiskey_disk/config.rb', line 84

def project_name
  specified_project_name || 'unnamed_project'
end

#specified_project_nameObject


52
53
54
55
56
# File 'lib/whiskey_disk/config.rb', line 52

def specified_project_name
  return false unless env_has_key?('to')
  return false unless ENV['to'] =~ /:/
  ENV['to'].split(/:/).first
end

#valid_path?(path) ⇒ Boolean

Returns:

  • (Boolean)

77
78
79
80
81
82
# File 'lib/whiskey_disk/config.rb', line 77

def valid_path?(path)
  return false unless path
  uri = URI.parse(path)
  return path if uri.scheme
  return path if File.file?(path)
end