Module: Shhh::App::Commands

Defined in:
lib/shhh/app/commands.rb,
lib/shhh/app/commands/command.rb,
lib/shhh/app/commands/show_help.rb,
lib/shhh/app/commands/print_key.rb,
lib/shhh/app/commands/open_editor.rb,
lib/shhh/app/commands/generate_key.rb,
lib/shhh/app/commands/show_version.rb,
lib/shhh/app/commands/show_examples.rb,
lib/shhh/app/commands/encrypt_decrypt.rb,
lib/shhh/app/commands/delete_keychain_item.rb

Defined Under Namespace

Classes: Command, DeleteKeychainItem, DependencyResolver, EncryptDecrypt, GenerateKey, OpenEditor, PrintKey, ShowExamples, ShowHelp, ShowVersion

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.commandsObject

Returns the value of attribute commands


21
22
23
# File 'lib/shhh/app/commands.rb', line 21

def commands
  @commands
end

.dependencyObject

Returns the value of attribute dependency


21
22
23
# File 'lib/shhh/app/commands.rb', line 21

def dependency
  @dependency
end

Class Method Details

.dependenciesObject


33
34
35
36
# File 'lib/shhh/app/commands.rb', line 33

def dependencies
  @dependencies ||= self.dependency.tsort
  @dependencies
end

.find_command_class(opts) ⇒ Object


45
46
47
48
49
50
# File 'lib/shhh/app/commands.rb', line 45

def find_command_class(opts)
  self.sorted_commands.each do |command_class|
    return command_class if command_class.options_satisfied_by?(opts.to_hash)
  end
  nil
end

.order(command_class, after) ⇒ Object


28
29
30
31
# File 'lib/shhh/app/commands.rb', line 28

def order(command_class, after)
  self.dependency[command_class.short_name].unshift(after) if after
  self.dependency[command_class.short_name].flatten!
end

.register(command_class) ⇒ Object


23
24
25
26
# File 'lib/shhh/app/commands.rb', line 23

def register(command_class)
  self.commands << command_class
  self.dependency[command_class.short_name] ||= []
end

.sorted_commandsObject

Sort commands based on the #dependencies array, which itself is sorted based on command dependencies.


40
41
42
43
# File 'lib/shhh/app/commands.rb', line 40

def sorted_commands
  @sorted_commands ||= self.commands.to_a.sort_by{|klass| dependencies.index(klass.short_name) }
  @sorted_commands
end