File: command_wrapper.rb

package info (click to toggle)
ruby-spring 1.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 364 kB
  • ctags: 429
  • sloc: ruby: 2,762; makefile: 6
file content (86 lines) | stat: -rw-r--r-- 1,416 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
require "spring/configuration"

module Spring
  class CommandWrapper
    attr_reader :name, :command

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

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

    def setup?
      @setup
    end

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

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

    def process_title
      [name, *ARGV].join(" ")
    end

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

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

    def binstub
      Spring.application_root_path.join(binstub_name)
    end

    def binstub_name
      "bin/#{name}"
    end

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

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