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

Methods inherited from Command

call

Constructor Details

#initialize(args) ⇒ Binstub

Returns a new instance of Binstub.



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

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

.descriptionObject



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

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

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/spring/client/binstub.rb', line 17

def call
  if Spring.command?(name)
    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



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

def command_binstub
  bindir.join(name)
end

#generate_command_binstubObject



61
62
63
64
65
66
67
68
# File 'lib/spring/client/binstub.rb', line 61

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

  command_binstub.chmod 0755
end

#generate_spring_binstubObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/spring/client/binstub.rb', line 36

def generate_spring_binstub
  File.write(spring_binstub, <<'CODE')
#!/usr/bin/env ruby

# This is a special way of invoking the spring gem in order to
# work around the performance issue discussed in
# https://github.com/rubygems/rubygems/pull/435

glob       = "{#{Gem::Specification.dirs.join(",")}}/spring-*.gemspec"
candidates = Dir[glob].to_a.sort

spec = Gem::Specification.load(candidates.last)

if spec
  spec.activate
  load spec.bin_file("spring")
else
  STDERR.puts "Could not find spring gem in #{Gem::Specification.dirs.join(", ")}."
  exit 1
end
CODE

  spring_binstub.chmod 0755
end

#spring_binstubObject



28
29
30
# File 'lib/spring/client/binstub.rb', line 28

def spring_binstub
  bindir.join("spring")
end