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

Returns a new instance of 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



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

def binstub
  Spring.application_root_path.join(binstub_name)
end

#binstub_nameObject



68
69
70
# File 'lib/spring/command_wrapper.rb', line 68

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



80
81
82
83
84
# File 'lib/spring/command_wrapper.rb', line 80

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

#execObject



72
73
74
75
76
77
78
# File 'lib/spring/command_wrapper.rb', line 72

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

#exec_nameObject



56
57
58
59
60
61
62
# File 'lib/spring/command_wrapper.rb', line 56

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

#gem_nameObject



48
49
50
51
52
53
54
# File 'lib/spring/command_wrapper.rb', line 48

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

#process_titleObject



44
45
46
# File 'lib/spring/command_wrapper.rb', line 44

def process_title
  [name, *ARGV].join(" ")
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

Returns:

  • (Boolean)


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

def setup?
  @setup
end