Class: UnimatrixCLI::Command
- Inherits:
-
Object
- Object
- UnimatrixCLI::Command
- Includes:
- UnimatrixParser
- Defined in:
- lib/unimatrix_cli/command.rb
Direct Known Subclasses
Alchemist::Rendition::ListCommand, Alchemist::RenditionProfile::AssignCommand, Alchemist::RenditionProfile::ListCommand, Alchemist::Video::CreateCommand, Alchemist::Video::DescribeCommand, Alchemist::VideoEncoder::CreateCommand, Alchemist::VideoEncoder::DescribeCommand, Alchemist::VideoEncoder::EncodeCommand, Alchemist::VideoEncoder::ListCommand, Archivist::Blueprint::CreateCommand, CLI, UnimatrixCLI::Cartographer::Region::CreateCommand, UnimatrixCLI::Cartographer::Region::ImportCitiesCommand, Iris::Stream::CreateCommand, Iris::Stream::DescribeCommand, Iris::StreamConverter::CreateCommand, Iris::StreamConverter::DescribeCommand, Iris::StreamEncoder::CreateCommand, Iris::StreamEncoder::DescribeCommand, Iris::StreamInput::CreateCommand, Iris::StreamInput::DescribeCommand, Iris::StreamOutput::CreateCommand, Iris::StreamOutput::DescribeCommand, Iris::StreamRecorder::CreateCommand, Iris::StreamRecorder::DescribeCommand, Iris::StreamTranscriber::CreateCommand, Iris::StreamTranscriber::DescribeCommand, Iris::StreamTransmutator::CreateCommand, Iris::StreamTransmutator::DescribeCommand, Keymaker::Policy::DestroyCommand, Keymaker::Policy::WriteCommand, Keymaker::Resource::ListCommand, Keymaker::ResourceOwner::FindCommand, Keymaker::ResourceOwner::InviteCommand, Keymaker::ResourceOwner::PoliciesCommand, Keymaker::ResourceOwner::RemoveCommand, Keymaker::ResourceServer::ListCommand, LoginCommand, LogoutCommand
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Command
constructor
A new instance of Command.
-
#read_file(path) ⇒ Object
—————————————————————————- File Reading.
- #validate(object, type) ⇒ Object
- #validate_collection(objects, type) ⇒ Object
-
#write(options) ⇒ Object
TODO add color options.
Methods included from UnimatrixParser
Constructor Details
#initialize ⇒ Command
Returns a new instance of Command.
8 9 10 |
# File 'lib/unimatrix_cli/command.rb', line 8 def initialize @options = self.class. end |
Class Method Details
.available_commands ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/unimatrix_cli/command.rb', line 122 def available_commands commands = Command.descendants commands.delete( UnimatrixCLI::CLI ) parsed_commands = commands.map do | command | command_words = command.to_s.split( '::' ) command_words.shift command_words.last.slice!( 'Command' ) command_words.map( &:underscore ).join( '::' ) end parsed_commands.sort.join( "\n" ) end |
.descendants ⇒ Object
118 119 120 |
# File 'lib/unimatrix_cli/command.rb', line 118 def descendants ObjectSpace.each_object( Class ).select { | klass | klass < self } end |
Instance Method Details
#read_file(path) ⇒ Object
File Reading
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/unimatrix_cli/command.rb', line 43 def read_file( path ) begin file = File.open( path, 'r' ) extension = path.split( '.' ).last.downcase contents = file_to_hash( file, extension ) rescue write( message: "There was a problem accessing and reading #{ path }", error: true ) ensure file.close end end |
#validate(object, type) ⇒ Object
24 25 26 27 28 |
# File 'lib/unimatrix_cli/command.rb', line 24 def validate( object, type ) object.present? && object.is_a?( "Unimatrix::#{ type }".constantize ) && object.errors.blank? rescue nil end |
#validate_collection(objects, type) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/unimatrix_cli/command.rb', line 30 def validate_collection( objects, type ) if objects.present? objects.all? do | object | validate( object, type ) end else false end end |
#write(options) ⇒ Object
TODO add color options
16 17 18 19 20 21 22 |
# File 'lib/unimatrix_cli/command.rb', line 16 def write( ) if [ :error ] $stderr.puts [ :message ] else $stdout.puts [ :message ] end end |