Class: PointCLI::Command
- Inherits:
-
Object
- Object
- PointCLI::Command
- Defined in:
- lib/point_cli/command.rb
Instance Method Summary collapse
- #call(*args) ⇒ Object
- #display_zone_information(zone) ⇒ Object
- #divider ⇒ Object
- #heading(title) ⇒ Object
-
#initialize(block) ⇒ Command
constructor
A new instance of Command.
- #select_zone(zone) ⇒ Object
- #use_hirb ⇒ Object
Constructor Details
#initialize(block) ⇒ Command
Returns a new instance of Command.
4 5 6 |
# File 'lib/point_cli/command.rb', line 4 def initialize(block) (class << self;self end).send :define_method, :command, &block end |
Instance Method Details
#call(*args) ⇒ Object
8 9 10 11 12 |
# File 'lib/point_cli/command.rb', line 8 def call(*args) arity = method(:command).arity args << nil while args.size < arity send :command, *args end |
#display_zone_information(zone) ⇒ Object
24 25 26 |
# File 'lib/point_cli/command.rb', line 24 def display_zone_information(zone) puts "Zone #{zone.inspect}" end |
#divider ⇒ Object
54 55 56 |
# File 'lib/point_cli/command.rb', line 54 def divider puts "=" * 80 end |
#heading(title) ⇒ Object
49 50 51 52 |
# File 'lib/point_cli/command.rb', line 49 def heading(title) puts "-" * 80 puts title end |
#select_zone(zone) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/point_cli/command.rb', line 29 def select_zone(zone) zones = Point::Zone.find(:all) zones = zones.select{|z| z.name.match(/\A#{zone}/) } if zones.size == 0 puts "There are no zones matching the domain you entered" Process.exit(1) elsif zones.size > 1 puts "There are multiple zones matching the domain you have posted. Which domain would" puts "you like to view?" zone_choice = choose do || for zone in zones .choice(zone.name) end end zones.select{|z| z.name == zone_choice}.first else zones.first end end |
#use_hirb ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/point_cli/command.rb', line 14 def use_hirb begin require 'hirb' extend Hirb::Console rescue LoadError puts "Hirb is not installed. Install hirb using '[sudo] gem install hirb' to get cool ASCII tables" Process.exit(1) end end |