Class: Hoof::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/hoof/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.expand_path(File.join("~/.hoof/", name)))
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



3
4
5
# File 'lib/hoof/application.rb', line 3

def app
  @app
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/hoof/application.rb', line 3

def name
  @name
end

#rootObject

Returns the value of attribute root.



3
4
5
# File 'lib/hoof/application.rb', line 3

def root
  @root
end

Instance Method Details

#load_rvmObject



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

#pidObject



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_fileObject



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

Returns:

  • (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

#sockObject



51
52
53
# File 'lib/hoof/application.rb', line 51

def sock
  @sock ||= File.join(root, 'tmp/sockets/unicorn.sock')
end

#startObject



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

Returns:

  • (Boolean)


36
37
38
# File 'lib/hoof/application.rb', line 36

def static_file? path
  File.file? File.join(root, 'public', path)
end

#stopObject



32
33
34
# File 'lib/hoof/application.rb', line 32

def stop
  Process.kill 'TERM', pid if running?
end