Class: ASIR::Environment
- Inherits:
-
Object
- Object
- ASIR::Environment
- Defined in:
- lib/asir/environment.rb
Instance Attribute Summary collapse
-
#adjective ⇒ Object
Returns the value of attribute adjective.
-
#config ⇒ Object
Returns the value of attribute config.
-
#config_rb ⇒ Object
Returns the value of attribute config_rb.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#log_dir ⇒ Object
Returns the value of attribute log_dir.
-
#log_file ⇒ Object
Returns the value of attribute log_file.
-
#object ⇒ Object
Returns the value of attribute object.
-
#options ⇒ Object
Returns the value of attribute options.
-
#phase ⇒ Object
Returns the value of attribute phase.
-
#pid_dir ⇒ Object
Returns the value of attribute pid_dir.
-
#verb ⇒ Object
Returns the value of attribute verb.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #asir_basename ⇒ Object
- #config!(phase, opts = { }) ⇒ Object
- #config_lambda ⇒ Object
- #find_writable_directory(kind, *list) ⇒ Object
-
#initialize ⇒ Environment
constructor
A new instance of Environment.
- #pid_file ⇒ Object
Constructor Details
#initialize ⇒ Environment
Returns a new instance of Environment.
11 12 13 14 15 |
# File 'lib/asir/environment.rb', line 11 def initialize @verbose = 0 @exit_code = 0 @options = { } end |
Instance Attribute Details
#adjective ⇒ Object
Returns the value of attribute adjective.
5 6 7 |
# File 'lib/asir/environment.rb', line 5 def adjective @adjective end |
#config ⇒ Object
Returns the value of attribute config.
6 7 8 |
# File 'lib/asir/environment.rb', line 6 def config @config end |
#config_rb ⇒ Object
Returns the value of attribute config_rb.
6 7 8 |
# File 'lib/asir/environment.rb', line 6 def config_rb @config_rb end |
#identifier ⇒ Object
Returns the value of attribute identifier.
5 6 7 |
# File 'lib/asir/environment.rb', line 5 def identifier @identifier end |
#log_dir ⇒ Object
Returns the value of attribute log_dir.
7 8 9 |
# File 'lib/asir/environment.rb', line 7 def log_dir @log_dir end |
#log_file ⇒ Object
Returns the value of attribute log_file.
7 8 9 |
# File 'lib/asir/environment.rb', line 7 def log_file @log_file end |
#object ⇒ Object
Returns the value of attribute object.
5 6 7 |
# File 'lib/asir/environment.rb', line 5 def object @object end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/asir/environment.rb', line 8 def @options end |
#phase ⇒ Object
Returns the value of attribute phase.
4 5 6 |
# File 'lib/asir/environment.rb', line 4 def phase @phase end |
#pid_dir ⇒ Object
Returns the value of attribute pid_dir.
7 8 9 |
# File 'lib/asir/environment.rb', line 7 def pid_dir @pid_dir end |
#verb ⇒ Object
Returns the value of attribute verb.
5 6 7 |
# File 'lib/asir/environment.rb', line 5 def verb @verb end |
#verbose ⇒ Object
Returns the value of attribute verbose.
9 10 11 |
# File 'lib/asir/environment.rb', line 9 def verbose @verbose end |
Instance Method Details
#asir_basename ⇒ Object
51 52 53 |
# File 'lib/asir/environment.rb', line 51 def asir_basename "asir-#{adjective}-#{object}-#{identifier}" end |
#config!(phase, opts = { }) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/asir/environment.rb', line 60 def config! phase, opts = { } ((@config ||= { })[phase] ||= [ begin opts[:phase] = phase save = { } opts.each do | k, v | save[k] = send(k) send(:"#{k}=", v) end $stderr.puts "#{self.class} calling #{config_rb} asir.phase=#{phase.inspect} ..." if @verbose >= 1 value = config_lambda.call(self) $stderr.puts "#{self.class} calling #{config_rb} asir.phase=#{phase.inspect} DONE" if @verbose >= 1 value ensure save.each do | k , v | send(:"#{k}=", v) end end ]).first end |
#config_lambda ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/asir/environment.rb', line 81 def config_lambda @config_lambda ||= ( file = config_rb $stderr.puts "#{self.class} loading #{file} ..." if @verbose >= 1 expr = File.read(file) expr = "begin; lambda do | asir |; #{expr}\n end; end" cfg = Object.new.send(:eval, expr, binding, file, 1) # cfg = load file # $stderr.puts "#{self.class} loading #{file} DONE" if @verbose >= 1 raise "#{file} did not return a Proc, returned a #{cfg.class}" unless Proc === cfg cfg ) end |
#find_writable_directory(kind, *list) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/asir/environment.rb', line 33 def find_writable_directory kind, *list list. reject { | p | ! p }. map { | p | File.(p) }. find { | p | File.writable?(p) } or raise "Cannot find writable directory for #{kind}" end |
#pid_file ⇒ Object
41 42 43 44 |
# File 'lib/asir/environment.rb', line 41 def pid_file @pid_file ||= "#{pid_dir}/#{asir_basename}.pid" end |