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_bundler ⇒ Object
- #load_rvm ⇒ Object
- #pid ⇒ Object
- #pid_file ⇒ Object
- #serve(data) ⇒ Object
- #serve_static(path) ⇒ Object
- #sock ⇒ Object
- #start ⇒ Object
- #static?(path) ⇒ Boolean
- #stop ⇒ Object
Constructor Details
#initialize(name) ⇒ Application
Returns a new instance of Application.
5 6 7 8 9 10 11 12 |
# File 'lib/hoof/application.rb', line 5 def initialize name @name = name @root = File.readlink(File.(File.join("~/.hoof/", name))) load_rvm load_bundler start 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_bundler ⇒ Object
33 34 35 36 |
# File 'lib/hoof/application.rb', line 33 def load_bundler #ENV['BUNDLE_GEMFILE'] = File.join(root, 'Gemfile') #require 'bundler/setup' end |
#load_rvm ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/hoof/application.rb', line 22 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
61 62 63 |
# File 'lib/hoof/application.rb', line 61 def pid File.read(pid_file).to_i end |
#pid_file ⇒ Object
57 58 59 |
# File 'lib/hoof/application.rb', line 57 def pid_file @pid_file ||= File.join(root, 'tmp/pids/unicorn.pid') end |
#serve(data) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/hoof/application.rb', line 46 def serve data UNIXSocket.open(sock) do |s| s.write data s.read end end |
#serve_static(path) ⇒ Object
42 43 44 |
# File 'lib/hoof/application.rb', line 42 def serve_static path File.read File.join(root, 'public', path) end |
#sock ⇒ Object
53 54 55 |
# File 'lib/hoof/application.rb', line 53 def sock @sock ||= "/tmp/hoof_#{name}.sock" end |
#start ⇒ Object
14 15 16 |
# File 'lib/hoof/application.rb', line 14 def start system "cd #{root} && bundle exec unicorn_rails -c #{File.join(File.dirname(__FILE__), 'unicorn_config.rb')} -l #{sock} -D" end |
#static?(path) ⇒ Boolean
38 39 40 |
# File 'lib/hoof/application.rb', line 38 def static? path File.file? File.join(root, 'public', path) end |
#stop ⇒ Object
18 19 20 |
# File 'lib/hoof/application.rb', line 18 def stop Process.kill "TERM", pid if File.exists? pid_file end |