Module: Sidekick
- Defined in:
- lib/sidekick.rb
Defined Under Namespace
Modules: Actions
Constant Summary collapse
- STOP_CALLBACKS =
called on shutdown
[]
- Context =
Module.new.extend(Actions)
Class Method Summary collapse
- .ensure_config_exists(path) ⇒ Object
- .run!(path = '.sidekick') ⇒ Object
- .stop(msg = nil) ⇒ Object
- .template_path ⇒ Object
Class Method Details
.ensure_config_exists(path) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/sidekick.rb', line 36 def self.ensure_config_exists(path) unless File.exists?(path) puts "Generate #{path}? (Y/n)" STDIN.gets =~ /^N|n/ ? exit : FileUtils.cp(template_path, path) end end |
.run!(path = '.sidekick') ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/sidekick.rb', line 26 def self.run!(path='.sidekick') ensure_config_exists(path) Signal.trap(:INT) { stop } EventMachine.run do Context.module_eval(IO.read(path), path) end end |
.stop(msg = nil) ⇒ Object
47 48 49 50 51 |
# File 'lib/sidekick.rb', line 47 def self.stop(msg=nil) STOP_CALLBACKS.each {|c| c.call } EventMachine.stop puts "\n#{msg}" if msg end |
.template_path ⇒ Object
43 44 45 |
# File 'lib/sidekick.rb', line 43 def self.template_path File.join File.dirname(__FILE__), *%w{sidekick template} end |