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.
-
#result ⇒ Object
Returns the value of attribute result.
Instance Method Summary collapse
- #command ⇒ Object
- #editor ⇒ 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
Constructor Details
#initialize(opts) ⇒ Application
Returns a new instance of Application.
15 16 17 18 19 20 21 22 |
# File 'lib/shhh/application.rb', line 15 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_input_handler initialize_key_handler initialize_action end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
6 7 8 |
# File 'lib/shhh/application.rb', line 6 def action @action end |
#args ⇒ Object
Returns the value of attribute args.
6 7 8 |
# File 'lib/shhh/application.rb', line 6 def args @args end |
#input_handler ⇒ Object
Returns the value of attribute input_handler.
6 7 8 |
# File 'lib/shhh/application.rb', line 6 def input_handler @input_handler end |
#key ⇒ Object
Returns the value of attribute key.
6 7 8 |
# File 'lib/shhh/application.rb', line 6 def key @key end |
#key_handler ⇒ Object
Returns the value of attribute key_handler.
6 7 8 |
# File 'lib/shhh/application.rb', line 6 def key_handler @key_handler end |
#opts ⇒ Object
Returns the value of attribute opts.
6 7 8 |
# File 'lib/shhh/application.rb', line 6 def opts @opts end |
#opts_hash ⇒ Object
Returns the value of attribute opts_hash.
6 7 8 |
# File 'lib/shhh/application.rb', line 6 def opts_hash @opts_hash end |
#result ⇒ Object
Returns the value of attribute result.
6 7 8 |
# File 'lib/shhh/application.rb', line 6 def result @result end |
Instance Method Details
#command ⇒ Object
62 63 64 65 |
# File 'lib/shhh/application.rb', line 62 def command @command_class ||= Shhh::App::Commands.find_command_class(opts) @command ||= @command_class.new(self) if @command_class end |
#editor ⇒ Object
67 68 69 |
# File 'lib/shhh/application.rb', line 67 def editor ENV['EDITOR'] || '/bin/vi' end |
#error(hash) ⇒ Object
71 72 73 |
# File 'lib/shhh/application.rb', line 71 def error(hash) hash end |
#execute ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/shhh/application.rb', line 45 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
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/shhh/application.rb', line 32 def execute! if args. || args. self.key = Shhh::App::PrivateKey::Handler.new(opts, input_handler).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
24 25 26 27 28 29 30 |
# File 'lib/shhh/application.rb', line 24 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
75 76 77 |
# File 'lib/shhh/application.rb', line 75 def initialize_input_handler(handler = ::Shhh::App::Input::Handler.new) self.input_handler = handler end |
#initialize_key_handler ⇒ Object
79 80 81 |
# File 'lib/shhh/application.rb', line 79 def initialize_key_handler self.key_handler = ::Shhh::App::PrivateKey::Handler.new(self.opts, input_handler) end |