Class: Hoof::Application
- Inherits:
-
Object
- Object
- Hoof::Application
- Defined in:
- lib/hoof/application.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#name ⇒ Object
Returns the value of attribute name.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
-
#initialize(name) ⇒ Application
constructor
A new instance of Application.
- #load_rvm ⇒ Object
- #pid ⇒ Object
- #pid_file ⇒ Object
- #running? ⇒ Boolean
- #serve(data) ⇒ Object
- #serve_static(path) ⇒ Object
- #sock ⇒ Object
- #start ⇒ Object
- #static_file?(path) ⇒ Boolean
- #stop ⇒ Object
Constructor Details
#initialize(name) ⇒ Application
Returns a new instance of Application.
5 6 7 8 |
# File 'lib/hoof/application.rb', line 5 def initialize name @name = name @root = File.readlink(File.(File.join("~/.hoof/", name))) end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
3 4 5 |
# File 'lib/hoof/application.rb', line 3 def app @app end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/hoof/application.rb', line 3 def name @name end |
#root ⇒ Object
Returns the value of attribute root.
3 4 5 |
# File 'lib/hoof/application.rb', line 3 def root @root end |
Instance Method Details
#load_rvm ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/hoof/application.rb', line 17 def load_rvm if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm') rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME'])) rvm_lib_path = File.join(rvm_path, 'lib') $LOAD_PATH.unshift rvm_lib_path require 'rvm' RVM.use_from_path! root end end |
#pid ⇒ Object
59 60 61 |
# File 'lib/hoof/application.rb', line 59 def pid File.read(pid_file).to_i if File.exists? pid_file end |
#pid_file ⇒ Object
55 56 57 |
# File 'lib/hoof/application.rb', line 55 def pid_file @pid_file ||= File.join(root, 'tmp/pids/unicorn.pid') end |
#running? ⇒ Boolean
28 29 30 |
# File 'lib/hoof/application.rb', line 28 def running? Daemons::Pid.running? pid end |
#serve(data) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/hoof/application.rb', line 44 def serve data UNIXSocket.open(sock) do |s| s.write data s.read end end |
#serve_static(path) ⇒ Object
40 41 42 |
# File 'lib/hoof/application.rb', line 40 def serve_static path File.read File.join(root, 'public', path) end |
#sock ⇒ Object
51 52 53 |
# File 'lib/hoof/application.rb', line 51 def sock @sock ||= File.join(root, 'tmp/sockets/unicorn.sock') end |
#start ⇒ Object
10 11 12 13 14 15 |
# File 'lib/hoof/application.rb', line 10 def start unless running? load_rvm system "cd #{root} && bundle exec unicorn_rails -c #{File.join(File.dirname(__FILE__), 'unicorn_config.rb')} -l #{sock} -D" end end |
#static_file?(path) ⇒ Boolean
36 37 38 |
# File 'lib/hoof/application.rb', line 36 def static_file? path File.file? File.join(root, 'public', path) end |
#stop ⇒ Object
32 33 34 |
# File 'lib/hoof/application.rb', line 32 def stop Process.kill 'TERM', pid if running? end |