Class: ConfigurationProvider

Inherits:
Object
  • Object
show all
Defined in:
app/providers/configuration_provider.rb

Instance Method Summary collapse

Constructor Details

#initializeConfigurationProvider

Returns a new instance of ConfigurationProvider.



12
13
14
15
# File 'app/providers/configuration_provider.rb', line 12

def initialize
  @config = defaults
  reload
end

Instance Method Details

#[](key) ⇒ Object



17
18
19
# File 'app/providers/configuration_provider.rb', line 17

def [](key)
  @config["environments"]["default"][key.to_s] rescue nil
end

#[]=(key, value) ⇒ Object



21
22
23
# File 'app/providers/configuration_provider.rb', line 21

def []=(key, value)
  @config["environments"]["default"][key.to_s] = value
end

#auth_endpointObject



46
47
48
49
50
# File 'app/providers/configuration_provider.rb', line 46

def auth_endpoint
  # Note: You can authenticate against any endpoint regardless of the location of your cloud account, however, to locate the proper service endpoints
  # you must authenticate against the correct cloud endpoint
  self.lon_region? ? Fog::Rackspace::UK_AUTH_ENDPOINT : Fog::Rackspace::US_AUTH_ENDPOINT
end

#default_pathObject



86
87
88
89
90
91
92
# File 'app/providers/configuration_provider.rb', line 86

def default_path
  if windows? && !cygwin?
    File.join(ENV['USERPROFILE'].gsub("\\","/"), ".rummrc")
  else
    File.join((ENV["HOME"] || "./"), ".rummrc")
  end
end

#deleteObject



78
79
80
81
82
83
84
# File 'app/providers/configuration_provider.rb', line 78

def delete
  @config = defaults
  File.delete(default_path) if File.exists? default_path
  true
rescue => e
  fail "Unable to delete #{default_path} - #{e.inspect}"
end

#lon_region?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/providers/configuration_provider.rb', line 42

def lon_region?
  region == "lon"
end

#regionObject



38
39
40
# File 'app/providers/configuration_provider.rb', line 38

def region
  region_to_str(ENV['REGION'] || self['region'])
end

#reloadObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/providers/configuration_provider.rb', line 52

def reload
  return false unless File.exists? default_path

  begin
    File.open default_path do |f|
      h = JSON.load f
      @config.merge! h
      true
    end
  rescue => e
    fail "Unable to read #{default_path} - #{e.inspect}"
  end
end

#saveObject



66
67
68
69
70
71
72
73
74
75
# File 'app/providers/configuration_provider.rb', line 66

def save
  begin
    File.open default_path, 'w' do |f|
      JSON.dump @config, f
      true
    end
  rescue => e
    fail "Unable to write #{default_path} - #{e.inspect}"
  end
end

#valueObject



8
9
10
# File 'app/providers/configuration_provider.rb', line 8

def value
  self
end