Class: PushyDaemon::Config

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.



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

def env
  @env
end

.filesObject (readonly)

Returns the value of attribute files.



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

def files
  @files
end

.nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

.specObject (readonly)

Returns the value of attribute spec.



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

def spec
  @spec
end

.versionObject (readonly)

Returns the value of attribute version.



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

def version
  @version
end

Class Method Details

.dumpObject



54
55
56
# File 'lib/pushyd/conf.rb', line 54

def self.dump
  self.to_hash.to_yaml
end

.prepare(args = {}) ⇒ Object



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
# File 'lib/pushyd/conf.rb', line 19

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]

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

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

end