Class: Cinchize::Cinchize
- Inherits:
-
Object
- Object
- Cinchize::Cinchize
- Defined in:
- lib/cinchize.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #_sym_hash(hsh) ⇒ Object
- #app_name ⇒ Object
- #clean_app_name ⇒ Object
- #dir ⇒ Object
-
#initialize(options, network, plugins, plugin_options) ⇒ Cinchize
constructor
A new instance of Cinchize.
- #restart ⇒ Object
- #running? ⇒ Boolean
- #start ⇒ Object
- #status ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options, network, plugins, plugin_options) ⇒ Cinchize
Returns a new instance of Cinchize.
69 70 71 72 73 74 |
# File 'lib/cinchize.rb', line 69 def initialize , network, plugins, @network = network @plugins = plugins @plugin_options = @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
67 68 69 |
# File 'lib/cinchize.rb', line 67 def @options end |
Instance Method Details
#_sym_hash(hsh) ⇒ Object
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/cinchize.rb', line 155 def _sym_hash hsh hsh.keys.inject({}) do |memo, key| if hsh[key].is_a? Hash memo[key.to_sym] = _sym_hash(hsh[key]) else memo[key.to_sym] = hsh[key] end memo end end |
#app_name ⇒ Object
76 77 78 |
# File 'lib/cinchize.rb', line 76 def app_name [:app_name] end |
#clean_app_name ⇒ Object
84 85 86 |
# File 'lib/cinchize.rb', line 84 def clean_app_name app_name.split('_', 2).last end |
#dir ⇒ Object
80 81 82 |
# File 'lib/cinchize.rb', line 80 def dir [:dir] end |
#restart ⇒ Object
88 89 90 91 |
# File 'lib/cinchize.rb', line 88 def restart stop start end |
#running? ⇒ Boolean
147 148 149 150 151 152 153 |
# File 'lib/cinchize.rb', line 147 def running? pidfile = Daemons::PidFile.new dir, app_name return false if pidfile.pid.nil? return Process.kill(0, pidfile.pid) != 0 rescue Errno::ESRCH => e return false end |
#start ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/cinchize.rb', line 93 def start if running? raise ArgumentError.new "#{clean_app_name} is already running" end puts "* starting #{clean_app_name}" daemon = Daemons::ApplicationGroup.new(app_name, { :ontop => [:ontop], :dir => dir, :dir_mode => [:dir_mode] }) app = daemon.new_application :mode => :none, :log_output => [:log_output] app.start network = _sym_hash(@network) plugins = @plugins = @plugin_options loop do bot = Cinch::Bot.new do configure do |c| c.load network c.plugins.plugins = plugins c.plugins. = end end bot.start end end |
#status ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/cinchize.rb', line 139 def status if running? puts "* #{clean_app_name} is running" else puts "* #{clean_app_name} is not running" end end |
#stop ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/cinchize.rb', line 126 def stop unless running? puts "* #{clean_app_name} is not running" return end pidfile = Daemons::PidFile.new dir, app_name puts "* stopping #{clean_app_name}" Process.kill("QUIT", pidfile.pid) File.delete(pidfile.filename) end |