Module: Bini
- Extended by:
- Bini
- Included in:
- Bini
- Defined in:
- lib/bini.rb,
lib/bini/sash.rb,
lib/bini/config.rb,
lib/bini/version.rb,
lib/bini/filemagic.rb,
lib/bini/optparser.rb
Defined Under Namespace
Modules: FileMagic Classes: OptionParser, Sash
Constant Summary collapse
- VERSION =
"0.5.4"
- Options =
OptionParser.new
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#defaults ⇒ Object
Returns the value of attribute defaults.
Instance Method Summary collapse
-
#configure {|_self| ... } ⇒ Object
Adds a rails style configure method (@benwoody’s unknown contribution).
- #daemonize(*params, &block) ⇒ Object
-
#keys ⇒ Object
Dynamic attribute’s based off the keys.
- #kill_daemon ⇒ Object
-
#parameters ⇒ Object
(also: #params)
List available parameters and values in those params.
-
#parameters? ⇒ Boolean
Returns true or false if all parameters are set.
- #pids ⇒ Object
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
4 5 6 |
# File 'lib/bini/config.rb', line 4 def config @config end |
#defaults ⇒ Object
Returns the value of attribute defaults.
10 11 12 |
# File 'lib/bini.rb', line 10 def defaults @defaults end |
Instance Method Details
#configure {|_self| ... } ⇒ Object
Adds a rails style configure method (@benwoody’s unknown contribution)
67 68 69 70 |
# File 'lib/bini.rb', line 67 def configure yield self parameters end |
#daemonize(*params, &block) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bini.rb', line 44 def daemonize(*params, &block) if params[0] && !params[0][:multiple_pids] && pids puts :info, "#{@name} appears to be running (#{pids}), only one allowed, exiting." exit end puts :info, "Forking to background." Process.daemon block.call end |
#keys ⇒ Object
Dynamic attribute’s based off the keys.
21 22 23 |
# File 'lib/bini.rb', line 21 def keys [:long_name, :cache_dir, :config_dir] end |
#kill_daemon ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/bini.rb', line 55 def kill_daemon if !pids puts :fatal, "No pids found, exiting." end pids.each do |p| puts :info, "Killing #{p}" `kill -TERM #{p}` end end |
#parameters ⇒ Object Also known as: params
List available parameters and values in those params
73 74 75 76 77 |
# File 'lib/bini.rb', line 73 def parameters @values = {} keys.each { |k| @values.merge! k => Bini.send(k) } @values end |
#parameters? ⇒ Boolean
Returns true or false if all parameters are set.
81 82 83 |
# File 'lib/bini.rb', line 81 def parameters? parameters.values.all? end |
#pids ⇒ Object
36 37 38 39 40 41 |
# File 'lib/bini.rb', line 36 def pids a = Sys::ProcTable.ps.select{|x| x.cmdline =~ /.*#{@name}.*-[dD].*/}.map {|x| x.pid} a.delete $$ return a if a.any? nil end |