Class: Appforce::Config

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

Constant Summary collapse

DEFAULT_CONFIG_PATH =

read in config file default location is root at runtime

"#{File.expand_path('~')}/.appforce"

Class Method Summary collapse

Class Method Details

.configObject



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

def self.config
  @config
end

.dump_example_configObject



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

def self.dump_example_config
  path = "#{File.expand_path('~')}/.appforce.example"
  h = {
    'api_host'    => 'https://afuka.synctree.com',
    'api_version' => 'api/v1',
    'api_token'   => 'PUT_API_TOKEN_HERE'
  }
  begin
    file = File.open(path, "w")
    file.write(h.to_yaml)
  rescue IOError => e
    logger.fatal "[#{self.name}##{__method__.to_s}] Appforce::ConfigDumpError -- #{e}"
    raise e
  ensure
    file.close unless file == nil
  end
end

.load_config(path = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/appforce/config.rb', line 10

def self.load_config(path=nil)
  begin
    temp = YAML::load(File.open(path.nil? ? DEFAULT_CONFIG_PATH : path))
    @config = OpenStruct.new temp
  rescue Exception => e
    logger.fatal "[#{self.name}##{__method__.to_s}] Appforce::Spawn::ConfigFileParseError"\
      " -- Config file appears to be malformed -- #{e}"
    raise e
  end  
end