Class: Spring::CommandWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/spring/command_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, command = nil) ⇒ CommandWrapper



7
8
9
10
11
# File 'lib/spring/command_wrapper.rb', line 7

def initialize(name, command = nil)
  @name    = name
  @command = command
  @setup   = false
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



5
6
7
# File 'lib/spring/command_wrapper.rb', line 5

def command
  @command
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/spring/command_wrapper.rb', line 5

def name
  @name
end

Instance Method Details

#binstubObject



60
61
62
# File 'lib/spring/command_wrapper.rb', line 60

def binstub
  Spring.application_root_path.join(binstub_name)
end

#binstub_nameObject



64
65
66
# File 'lib/spring/command_wrapper.rb', line 64

def binstub_name
  "bin/#{name}"
end

#callObject



36
37
38
39
40
41
42
# File 'lib/spring/command_wrapper.rb', line 36

def call
  if command.respond_to?(:call)
    command.call
  else
    load exec
  end
end

#descriptionObject



13
14
15
16
17
18
19
# File 'lib/spring/command_wrapper.rb', line 13

def description
  if command.respond_to?(:description)
    command.description
  else
    "Runs the #{name} command"
  end
end

#env(args) ⇒ Object



76
77
78
79
80
# File 'lib/spring/command_wrapper.rb', line 76

def env(args)
  if command.respond_to?(:env)
    command.env(args)
  end
end

#execObject



68
69
70
71
72
73
74
# File 'lib/spring/command_wrapper.rb', line 68

def exec
  if binstub.exist?
    binstub.to_s
  else
    Gem.bin_path(gem_name, exec_name)
  end
end

#exec_nameObject



52
53
54
55
56
57
58
# File 'lib/spring/command_wrapper.rb', line 52

def exec_name
  if command.respond_to?(:exec_name)
    command.exec_name
  else
    name
  end
end

#gem_nameObject



44
45
46
47
48
49
50
# File 'lib/spring/command_wrapper.rb', line 44

def gem_name
  if command.respond_to?(:gem_name)
    command.gem_name
  else
    exec_name
  end
end

#setupObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/spring/command_wrapper.rb', line 25

def setup
  if !setup? && command.respond_to?(:setup)
    command.setup
    @setup = true
    return true
  else
    @setup = true
    return false
  end
end

#setup?Boolean



21
22
23
# File 'lib/spring/command_wrapper.rb', line 21

def setup?
  @setup
end