Class: Openup::Commander
- Inherits:
-
Object
- Object
- Openup::Commander
- Defined in:
- lib/openup/commander.rb
Class Method Summary collapse
Instance Method Summary collapse
- #current_directory ⇒ Object
-
#initialize(args) ⇒ Commander
constructor
A new instance of Commander.
- #linkfile ⇒ Object
- #linkfile_exists? ⇒ Boolean
- #linkfile_path ⇒ Object
- #run! ⇒ Object
- #show_help ⇒ Object
Constructor Details
#initialize(args) ⇒ Commander
Returns a new instance of Commander.
41 42 43 |
# File 'lib/openup/commander.rb', line 41 def initialize(args) @arguments = args end |
Class Method Details
.run!(args) ⇒ Object
37 38 39 |
# File 'lib/openup/commander.rb', line 37 def self.run!(args) new(args).run! end |
Instance Method Details
#current_directory ⇒ Object
69 70 71 |
# File 'lib/openup/commander.rb', line 69 def current_directory @current_directory ||= `pwd`.strip end |
#linkfile ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/openup/commander.rb', line 81 def linkfile @linkfile ||= begin if linkfile_exists? require 'json' JSON.parse(File.open(linkfile_path).read) else nil end end end |
#linkfile_exists? ⇒ Boolean
77 78 79 |
# File 'lib/openup/commander.rb', line 77 def linkfile_exists? File.exists?(linkfile_path) end |
#linkfile_path ⇒ Object
73 74 75 |
# File 'lib/openup/commander.rb', line 73 def linkfile_path File.join(current_directory, '/Linkfile') end |
#run! ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/openup/commander.rb', line 45 def run! if !linkfile_exists? puts "No Linkfile in path #{current_directory}!" else link = @arguments.first command = Command.new(linkfile[link]) if linkfile[link] if !link show_help elsif command && link command.run! else # unknown link puts "Unknown link #{command} in Linkfile" end end end |
#show_help ⇒ Object
63 64 65 66 67 |
# File 'lib/openup/commander.rb', line 63 def show_help linkfile.each do |k, v| puts "\t#{k}: #{v}" end end |