Class: Tainers::CLI::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/tainers/cli.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec = {}) ⇒ Command

Returns a new instance of Command.



84
85
86
# File 'lib/tainers/cli.rb', line 84

def initialize(spec={})
  @specification = Tainers.specify(spec)
end

Instance Attribute Details

#specificationObject (readonly)

Returns the value of attribute specification.



82
83
84
# File 'lib/tainers/cli.rb', line 82

def specification
  @specification
end

Class Method Details

.commandsObject



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_helpObject



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_helpObject



114
115
116
# File 'lib/tainers/cli.rb', line 114

def self.ensure_help
  "Ensures specified container exists, by name."
end

.exists_helpObject



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_helpObject



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_commandObject



100
101
102
103
# File 'lib/tainers/cli.rb', line 100

def create_command
  return 0 if specification.create
  1
end

#ensure_commandObject



109
110
111
112
# File 'lib/tainers/cli.rb', line 109

def ensure_command
  return 0 if specification.ensure
  255
end

#exists_commandObject



118
119
120
121
# File 'lib/tainers/cli.rb', line 118

def exists_command
  return 0 if specification.exists?
  1
end

#name_commandObject



127
128
129
130
# File 'lib/tainers/cli.rb', line 127

def name_command
  STDOUT.print "#{specification.name}\n"
  0
end