Module: Sym::App::Commands

Defined in:
lib/sym/app/commands.rb,
lib/sym/app/commands/decrypt.rb,
lib/sym/app/commands/encrypt.rb,
lib/sym/app/commands/print_key.rb,
lib/sym/app/commands/show_help.rb,
lib/sym/app/commands/open_editor.rb,
lib/sym/app/commands/base_command.rb,
lib/sym/app/commands/generate_key.rb,
lib/sym/app/commands/show_version.rb,
lib/sym/app/commands/show_examples.rb,
lib/sym/app/commands/bash_completion.rb,
lib/sym/app/commands/keychain_add_key.rb,
lib/sym/app/commands/password_protect_key.rb

Defined Under Namespace

Classes: BaseCommand, BashCompletion, Decrypt, DependencyResolver, Encrypt, GenerateKey, KeychainAddKey, OpenEditor, PasswordProtectKey, PrintKey, ShowExamples, ShowHelp, ShowVersion

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.commandsObject

Returns the value of attribute commands.



20
21
22
# File 'lib/sym/app/commands.rb', line 20

def commands
  @commands
end

.dependencyObject

Returns the value of attribute dependency.



20
21
22
# File 'lib/sym/app/commands.rb', line 20

def dependency
  @dependency
end

Class Method Details

.dependenciesObject



32
33
34
35
# File 'lib/sym/app/commands.rb', line 32

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

.find_command_class(opts) ⇒ Object



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

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

.order(command_class, after) ⇒ Object



27
28
29
30
# File 'lib/sym/app/commands.rb', line 27

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



22
23
24
25
# File 'lib/sym/app/commands.rb', line 22

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.



39
40
41
42
# File 'lib/sym/app/commands.rb', line 39

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