Class: Spring::Client::Binstub
- Defined in:
- lib/spring/client/binstub.rb
Defined Under Namespace
Classes: RailsCommand
Instance Attribute Summary collapse
-
#bindir ⇒ Object
readonly
Returns the value of attribute bindir.
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
Attributes inherited from Command
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #fallback(name, command) ⇒ Object
- #find_commands(name) ⇒ Object
- #generate_binstub(name, command) ⇒ Object
-
#initialize(args) ⇒ Binstub
constructor
A new instance of Binstub.
Constructor Details
#initialize(args) ⇒ Binstub
Returns a new instance of Binstub.
25 26 27 28 29 30 |
# File 'lib/spring/client/binstub.rb', line 25 def initialize(args) super @bindir = env.root.join("bin") @commands = args.drop(1).inject({}) { |mem, name| mem.merge(find_commands(name)) } end |
Instance Attribute Details
#bindir ⇒ Object (readonly)
Returns the value of attribute bindir.
4 5 6 |
# File 'lib/spring/client/binstub.rb', line 4 def bindir @bindir end |
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
4 5 6 |
# File 'lib/spring/client/binstub.rb', line 4 def commands @commands 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 |
.description ⇒ Object
6 7 8 |
# File 'lib/spring/client/binstub.rb', line 6 def self.description "Generate spring based binstubs. Use --all to generate a binstub for all known commands." end |
Instance Method Details
#call ⇒ Object
51 52 53 54 |
# File 'lib/spring/client/binstub.rb', line 51 def call bindir.mkdir unless bindir.exist? commands.each { |name, command| generate_binstub(name, command) } end |
#fallback(name, command) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/spring/client/binstub.rb', line 71 def fallback(name, command) if command.respond_to?(:fallback) command.fallback else %{exec "bundle", "exec", "#{name}", *ARGV} end end |
#find_commands(name) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/spring/client/binstub.rb', line 32 def find_commands(name) case name when "--all" commands = Spring.commands commands.delete_if { |name, _| name.start_with?("rails_") } commands["rails"] = RailsCommand.new commands when "rails" { name => RailsCommand.new } else if command = Spring.commands[name] { name => command } else $stderr.puts "The '#{name}' command is not known to spring." exit 1 end end end |
#generate_binstub(name, command) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/spring/client/binstub.rb', line 56 def generate_binstub(name, command) File.write(bindir.join(name), <<CODE) #!/usr/bin/env ruby if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty? #{fallback(name, command).strip.gsub(/^/, " ")} else ARGV.unshift "#{name}" load Gem.bin_path("spring", "spring") end CODE bindir.join(name).chmod 0755 end |