Class: Shhh::Application
- Inherits:
-
Object
- Object
- Shhh::Application
- Defined in:
- lib/shhh/application.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#args ⇒ Object
Returns the value of attribute args.
-
#input_handler ⇒ Object
Returns the value of attribute input_handler.
-
#key ⇒ Object
Returns the value of attribute key.
-
#key_handler ⇒ Object
Returns the value of attribute key_handler.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#opts_hash ⇒ Object
Returns the value of attribute opts_hash.
-
#password_cache ⇒ Object
Returns the value of attribute password_cache.
-
#result ⇒ Object
Returns the value of attribute result.
Instance Method Summary collapse
- #command ⇒ Object
- #editor ⇒ Object
- #editors_to_try ⇒ Object
- #error(hash) ⇒ Object
- #execute ⇒ Object
- #execute! ⇒ Object
-
#initialize(opts) ⇒ Application
constructor
A new instance of Application.
- #initialize_action ⇒ Object
- #initialize_input_handler(handler = ::Shhh::App::Input::Handler.new) ⇒ Object
- #initialize_key_handler ⇒ Object
- #initialize_password_cache ⇒ Object
Constructor Details
#initialize(opts) ⇒ Application
Returns a new instance of Application.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/shhh/application.rb', line 18 def initialize(opts) self.opts = opts self.opts_hash = opts.respond_to?(:to_hash) ? opts.to_hash : opts self.args = ::Shhh::App::Args.new(opts_hash) initialize_password_cache initialize_input_handler initialize_key_handler initialize_action end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
8 9 10 |
# File 'lib/shhh/application.rb', line 8 def action @action end |
#args ⇒ Object
Returns the value of attribute args.
8 9 10 |
# File 'lib/shhh/application.rb', line 8 def args @args end |
#input_handler ⇒ Object
Returns the value of attribute input_handler.
8 9 10 |
# File 'lib/shhh/application.rb', line 8 def input_handler @input_handler end |
#key ⇒ Object
Returns the value of attribute key.
8 9 10 |
# File 'lib/shhh/application.rb', line 8 def key @key end |
#key_handler ⇒ Object
Returns the value of attribute key_handler.
8 9 10 |
# File 'lib/shhh/application.rb', line 8 def key_handler @key_handler end |
#opts ⇒ Object
Returns the value of attribute opts.
8 9 10 |
# File 'lib/shhh/application.rb', line 8 def opts @opts end |
#opts_hash ⇒ Object
Returns the value of attribute opts_hash.
8 9 10 |
# File 'lib/shhh/application.rb', line 8 def opts_hash @opts_hash end |
#password_cache ⇒ Object
Returns the value of attribute password_cache.
8 9 10 |
# File 'lib/shhh/application.rb', line 8 def password_cache @password_cache end |
#result ⇒ Object
Returns the value of attribute result.
8 9 10 |
# File 'lib/shhh/application.rb', line 8 def result @result end |
Instance Method Details
#command ⇒ Object
68 69 70 71 72 |
# File 'lib/shhh/application.rb', line 68 def command @command_class ||= Shhh::App::Commands.find_command_class(opts) @command ||= @command_class.new(self) if @command_class @command end |
#editor ⇒ Object
74 75 76 |
# File 'lib/shhh/application.rb', line 74 def editor editors_to_try.find { |editor| File.exist?(editor) } end |
#editors_to_try ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/shhh/application.rb', line 78 def editors_to_try [ ENV['EDITOR'], '/usr/bin/vim', '/usr/local/bin/vim', '/bin/vim', '/sbin/vim', '/usr/sbin/vim', '/usr/bin/vi', '/usr/local/bin/vi', '/bin/vi', '/sbin/vi' ] end |
#error(hash) ⇒ Object
93 94 95 |
# File 'lib/shhh/application.rb', line 93 def error(hash) hash end |
#execute ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/shhh/application.rb', line 51 def execute execute! rescue ::OpenSSL::Cipher::CipherError => e error type: 'Cipher Error', details: e., reason: 'Perhaps either the secret is invalid, or encrypted data is corrupt.', exception: e rescue Shhh::Errors::Error => e error type: e.class.name.split(/::/)[-1], details: e. rescue StandardError => e error exception: e end |
#execute! ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/shhh/application.rb', line 37 def execute! if !args.generate_key? && (args.require_key? || args.specify_key?) self.key = Shhh::App::PrivateKey::Handler.new(opts, input_handler, password_cache).key raise Shhh::Errors::NoPrivateKeyFound.new('Private key is required') unless self.key end unless command raise Shhh::Errors::InsufficientOptionsError.new( 'Can not determine what to do from the options ' + opts_hash.keys.reject { |k| !opts[k] }.to_s) end self.result = command.execute end |
#initialize_action ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/shhh/application.rb', line 29 def initialize_action self.action = if opts[:encrypt] then :encr elsif opts[:decrypt] :decr end end |
#initialize_input_handler(handler = ::Shhh::App::Input::Handler.new) ⇒ Object
97 98 99 |
# File 'lib/shhh/application.rb', line 97 def initialize_input_handler(handler = ::Shhh::App::Input::Handler.new) self.input_handler = handler end |
#initialize_key_handler ⇒ Object
101 102 103 |
# File 'lib/shhh/application.rb', line 101 def initialize_key_handler self.key_handler = ::Shhh::App::PrivateKey::Handler.new(self.opts, input_handler, password_cache) end |
#initialize_password_cache ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'lib/shhh/application.rb', line 105 def initialize_password_cache args = {} args[:provider] = Coin args[:timeout] = opts[:password_timeout].to_i if opts[:password_timeout] args[:enabled] = false if opts[:no_password_cache] self.password_cache = Shhh::App::Password::Cache.instance.configure(args) end |