Class: Spring::Client::Binstub

Inherits:
Command
  • Object
show all
Defined in:
lib/spring/client/binstub.rb

Instance Attribute Summary collapse

Attributes inherited from Command

#args, #env

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Binstub

Returns a new instance of Binstub.



15
16
17
18
19
20
21
# File 'lib/spring/client/binstub.rb', line 15

def initialize(args)
  super

  @bindir  = env.root.join("bin")
  @name    = args[1]
  @command = Spring.commands[name]
end

Instance Attribute Details

#bindirObject (readonly)

Returns the value of attribute bindir.



4
5
6
# File 'lib/spring/client/binstub.rb', line 4

def bindir
  @bindir
end

#commandObject (readonly)

Returns the value of attribute command.



4
5
6
# File 'lib/spring/client/binstub.rb', line 4

def command
  @command
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/spring/client/binstub.rb', line 4

def name
  @name
end

Class Method Details

.call(args) ⇒ Object



10
11
12
13
# File 'lib/spring/client/binstub.rb', line 10

def self.call(args)
  require "spring/commands"
  super
end

.descriptionObject



6
7
8
# File 'lib/spring/client/binstub.rb', line 6

def self.description
  "Generate spring based binstubs."
end

Instance Method Details

#binstubObject



33
34
35
# File 'lib/spring/client/binstub.rb', line 33

def binstub
  bindir.join(name)
end

#callObject



23
24
25
26
27
28
29
30
31
# File 'lib/spring/client/binstub.rb', line 23

def call
  if command || name == "rails"
    bindir.mkdir unless bindir.exist?
    generate_binstub
  else
    $stderr.puts "The '#{name}' command is not known to spring."
    exit 1
  end
end

#fallbackObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/spring/client/binstub.rb', line 52

def fallback
  if command.respond_to?(:fallback)
    command.fallback
  elsif name == "rails"
    <<CODE
APP_PATH = File.expand_path('../../config/application',  __FILE__)
require_relative '../config/boot'
require 'rails/commands'
CODE
  else
    %{exec "bundle", "exec", "#{name}", *ARGV}
  end
end

#generate_binstubObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/spring/client/binstub.rb', line 37

def generate_binstub
  File.write(binstub, <<CODE)
#!/usr/bin/env ruby

if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
#{fallback.strip.gsub(/^/, "  ")}
else
  ARGV.unshift "#{name}"
  load Gem.bin_path("spring", "spring")
end
CODE

  binstub.chmod 0755
end