Class: Qwandry::Launcher
- Inherits:
-
Object
- Object
- Qwandry::Launcher
- Defined in:
- lib/qwandry/launcher.rb
Instance Attribute Summary collapse
-
#editor ⇒ Object
The default editor to be used by Qwandry#launch.
Instance Method Summary collapse
-
#find(*pattern) ⇒ Object
Searches all of the loaded repositories for ‘name`.
-
#launch(package, editor = nil) ⇒ Object
Launches a Package or path represented by a String.
Instance Attribute Details
#editor ⇒ Object
The default editor to be used by Qwandry#launch.
6 7 8 |
# File 'lib/qwandry/launcher.rb', line 6 def editor @editor end |
Instance Method Details
#find(*pattern) ⇒ Object
Searches all of the loaded repositories for ‘name`
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/qwandry/launcher.rb', line 9 def find(*pattern) # Create a glob pattern from the user's input, for instance # ["rails","2.3"] => "rails*2.3*" pattern = pattern.join('*') pattern << '*' unless pattern =~ /\*$/ packages = [] repositories = Qwandry::Configuration.repositories repositories.each do |repo| packages.concat(repo.scan(pattern)) end differentiate packages packages end |
#launch(package, editor = nil) ⇒ Object
Launches a Package or path represented by a String. Unless ‘editor` will check against the environment by default.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/qwandry/launcher.rb', line 27 def launch(package, editor=nil) editor ||= @editor || ENV['QWANDRY_EDITOR'] || ENV['VISUAL'] || ENV['EDITOR'] if (!editor) || (editor =~ /^\s*$/) # if the editor is not set, or is blank, exit with a message: puts "Please set QWANDRY_EDITOR, VISUAL or EDITOR, or pass in an editor to use (-e editor)" if STDOUT.tty? print "Or, select an editor now: " editor = gets else exit 1 end end paths = package.is_a?(String) ? [package] : package.paths # Editors may have options, 'mate -w' for instance = editor.strip.split(/\s+/) Dir.chdir(File.dirname paths.first) do # Launch the editor with its options and any paths that we have been passed system(*( + paths)) end end |