Class: PushyDaemon::Conf

Inherits:
Object
  • Object
show all
Extended by:
Chamber
Defined in:
lib/pushyd/conf.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.envObject (readonly)

Returns the value of attribute env.



15
16
17
# File 'lib/pushyd/conf.rb', line 15

def env
  @env
end

.filesObject (readonly)

Returns the value of attribute files.



13
14
15
# File 'lib/pushyd/conf.rb', line 13

def files
  @files
end

.nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/pushyd/conf.rb', line 11

def name
  @name
end

.specObject (readonly)

Returns the value of attribute spec.



12
13
14
# File 'lib/pushyd/conf.rb', line 12

def spec
  @spec
end

.versionObject (readonly)

Returns the value of attribute version.



14
15
16
# File 'lib/pushyd/conf.rb', line 14

def version
  @version
end

Class Method Details

.dumpObject



56
57
58
# File 'lib/pushyd/conf.rb', line 56

def self.dump
  self.to_hash.to_yaml
end

.prepare(args = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/pushyd/conf.rb', line 18

def self.prepare args = {}
  # Context parameters
  raise PushyDaemon::ConfigMissingParameter, "missing root" unless (@root = args[:root])
  raise PushyDaemon::ConfigMissingParameter, "missing env"  unless (@env = args[:env])

  # Gemspec parameter
  gemspec_path = "#{args[:root]}/#{args[:gemspec]}.gemspec"
  raise PushyDaemon::ConfigMissingParameter, "missing gemspec" unless args[:gemspec]
  raise PushyDaemon::ConfigMissingParameter, "gemspec file not found: #{gemspec_path}" unless File.exist?(gemspec_path)

  # Load Gemspec
  @spec     = Gem::Specification::load gemspec_path
  @name     = @spec.name
  @version  = @spec.version
  raise PushyDaemon::ConfigMissingParameter, "missing name" unless @name

  # Init Chamber (defaults, etc, cmdline)
  @files = ["#{args[:root]}/defaults.yml"]
  @files << File.expand_path("/etc/#{@name}.yml")
  @files << args[:config].to_s if args[:config]

  # Load configuration files
  load files: @files, namespaces: { environment: @env }

  # Try to access any key to force parsing of the files
  self[:dummy]

  # Override some values
  self[:log] = args[:log].to_s if args[:log]

rescue Psych::SyntaxError => e
  raise PushyDaemon::ConfigParseError, e.message

rescue Exception => e
  raise PushyDaemon::ConfigParseError, e.message

end