Class: Tainers::CLI::Command
- Inherits:
-
Object
- Object
- Tainers::CLI::Command
- Defined in:
- lib/tainers/cli.rb
Instance Attribute Summary collapse
-
#specification ⇒ Object
readonly
Returns the value of attribute specification.
Class Method Summary collapse
- .commands ⇒ Object
- .create_help ⇒ Object
- .ensure_help ⇒ Object
- .exists_help ⇒ Object
- .name_help ⇒ Object
Instance Method Summary collapse
- #create_command ⇒ Object
- #ensure_command ⇒ Object
- #exists_command ⇒ Object
-
#initialize(spec = {}) ⇒ Command
constructor
A new instance of Command.
- #name_command ⇒ Object
Constructor Details
Instance Attribute Details
#specification ⇒ Object (readonly)
Returns the value of attribute specification.
82 83 84 |
# File 'lib/tainers/cli.rb', line 82 def specification @specification end |
Class Method Details
.commands ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/tainers/cli.rb', line 88 def self.commands cmds = instance_methods.collect {|m| m.to_s}.find_all {|m| m.to_s =~ /_command$/}.collect {|n| n.to_s[0..-9] } cmds.collect do |name| helper = "#{name}_help".to_sym if respond_to? helper [name, send(helper)] else [name, ''] end end end |
.create_help ⇒ Object
105 106 107 |
# File 'lib/tainers/cli.rb', line 105 def self.create_help "Creates specified container, if it doesn't already exist; exits with 0 on creation, 1 if already exists." end |
.ensure_help ⇒ Object
114 115 116 |
# File 'lib/tainers/cli.rb', line 114 def self.ensure_help "Ensures specified container exists, by name." end |
.exists_help ⇒ Object
123 124 125 |
# File 'lib/tainers/cli.rb', line 123 def self.exists_help "Exits with 0 (true) if specified container exists, by name; 1 (false) if not." end |
.name_help ⇒ Object
132 133 134 |
# File 'lib/tainers/cli.rb', line 132 def self.name_help "Prints the specified container's name on stdout." end |
Instance Method Details
#create_command ⇒ Object
100 101 102 103 |
# File 'lib/tainers/cli.rb', line 100 def create_command return 0 if specification.create 1 end |
#ensure_command ⇒ Object
109 110 111 112 |
# File 'lib/tainers/cli.rb', line 109 def ensure_command return 0 if specification.ensure 255 end |
#exists_command ⇒ Object
118 119 120 121 |
# File 'lib/tainers/cli.rb', line 118 def exists_command return 0 if specification.exists? 1 end |
#name_command ⇒ Object
127 128 129 130 |
# File 'lib/tainers/cli.rb', line 127 def name_command STDOUT.print "#{specification.name}\n" 0 end |