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
# File 'lib/spring/client/binstub.rb', line 15

def initialize(args)
  super

  @bindir = env.root.join("bin")
  @name   = args[1]
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

#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

#callObject



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

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

#command_binstubObject



37
38
39
# File 'lib/spring/client/binstub.rb', line 37

def command_binstub
  bindir.join(name)
end

#generate_command_binstubObject



66
67
68
69
70
71
72
73
# File 'lib/spring/client/binstub.rb', line 66

def generate_command_binstub
  File.write(command_binstub, "#!/usr/bin/env bash\nexec $(dirname $0)/spring \#{name} \"$@\"\n")

  command_binstub.chmod 0755
end

#generate_spring_binstubObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/spring/client/binstub.rb', line 41

def generate_spring_binstub
  File.write(spring_binstub, "#!/usr/bin/env ruby\n\n# This is a special way of invoking the spring gem in order to\n# work around the performance issue discussed in\n# https://github.com/rubygems/rubygems/pull/435\n\nglob       = \"{\#{Gem::Specification.dirs.join(\",\")}}/spring-*.gemspec\"\ncandidates = Dir[glob].to_a.sort\n\nspec = Gem::Specification.load(candidates.last)\n\nif spec\n  spec.activate\n  load spec.bin_file(\"spring\")\nelse\n  $stderr.puts \"Could not find spring gem in \#{Gem::Specification.dirs.join(\", \")}.\"\n  exit 1\nend\n")

  spring_binstub.chmod 0755
end

#spring_binstubObject



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

def spring_binstub
  bindir.join("spring")
end