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
9
10
11
12
# File 'lib/hoof/application.rb', line 5

def initialize name
  @name = name
  @root = File.readlink(File.expand_path(File.join("~/.hoof/", name)))

  load_rvm
  load_bundler
  start
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_bundlerObject



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_rvmObject



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

#pidObject



61
62
63
# File 'lib/hoof/application.rb', line 61

def pid
  File.read(pid_file).to_i
end

#pid_fileObject



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

#sockObject



53
54
55
# File 'lib/hoof/application.rb', line 53

def sock
  @sock ||= "/tmp/hoof_#{name}.sock"
end

#startObject



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

Returns:

  • (Boolean)


38
39
40
# File 'lib/hoof/application.rb', line 38

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

#stopObject



18
19
20
# File 'lib/hoof/application.rb', line 18

def stop
  Process.kill "TERM", pid if File.exists? pid_file
end