Class: Spore::Config

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

Direct Known Subclasses

DeploymentConfig, LocalConfig

Constant Summary collapse

DEPLOYMENT_VAR =
"SPORE_DEPLOYMENT"
CONFIG_FILE =
"config.json"
DEFAULT_CONFIG =
File.expand_path(
"../config/default.json", File.dirname(__FILE__))

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



7
8
9
# File 'lib/spore/config.rb', line 7

def api
  @api
end

#environmentObject (readonly)

Returns the value of attribute environment.



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

def environment
  @environment
end

Class Method Details

.is_deployment?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/spore/config.rb', line 15

def is_deployment?
  !ENV[DEPLOYMENT_VAR].nil?
end

.loadObject



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

def load
  if is_deployment?
    Spore::DeploymentConfig.new
  else
    Spore::LocalConfig.new
  end
end

Instance Method Details

#configObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/spore/config.rb', line 28

def config
  @config ||= begin
    file = File.read DEFAULT_CONFIG
    hash  = JSON.parse file
    config_file = File.join(ENV["SPORE_HOME"] || "~/.spore", CONFIG_FILE)
    begin
      hash.update(JSON.parse(File.read(File.expand_path(config_file))))
    rescue Errno::ENOENT
      # ~/.spore/config.json doesn't exist, so just use the default config
      hash
    end
  end
end

#fetch(app_id, cell_id) ⇒ Object



42
43
44
# File 'lib/spore/config.rb', line 42

def fetch(app_id, cell_id)
  api.get_cell(app_id, environment, cell_id)["value"]
end

#spore_fileObject



46
47
48
# File 'lib/spore/config.rb', line 46

def spore_file
  File.expand_path(config["sporeFile"])
end