Class: Sym::Application
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.
-
#key_source ⇒ Object
Returns the value of attribute key_source.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#opts_original ⇒ Object
Returns the value of attribute opts_original.
-
#output ⇒ Object
Returns the value of attribute output.
-
#password_cache ⇒ Object
Returns the value of attribute password_cache.
-
#provided_options ⇒ Object
Returns the value of attribute provided_options.
-
#result ⇒ Object
Returns the value of attribute result.
Instance Method Summary collapse
- #command ⇒ Object
- #editor ⇒ Object
- #execute ⇒ Object
- #execute! ⇒ Object
-
#initialize(opts) ⇒ Application
constructor
A new instance of Application.
- #log(*args) ⇒ Object
- #provided_flags ⇒ Object
- #provided_safe_options ⇒ Object
- #provided_value_options ⇒ Object
Constructor Details
#initialize(opts) ⇒ Application
Returns a new instance of Application.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sym/application.rb', line 24 def initialize(opts) self.opts_original = opts self.opts = opts.is_a?(Hash) ? opts : opts.to_hash process_negated_option(opts[:negate]) if opts[:negate] self.args = ::Sym::App::Args.new(self.) initialize_output_stream initialize_action initialize_data_source initialize_password_cache initialize_input_handler end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
10 11 12 |
# File 'lib/sym/application.rb', line 10 def action @action end |
#args ⇒ Object
Returns the value of attribute args.
10 11 12 |
# File 'lib/sym/application.rb', line 10 def args @args end |
#input_handler ⇒ Object
Returns the value of attribute input_handler.
10 11 12 |
# File 'lib/sym/application.rb', line 10 def input_handler @input_handler end |
#key ⇒ Object
Returns the value of attribute key.
10 11 12 |
# File 'lib/sym/application.rb', line 10 def key @key end |
#key_handler ⇒ Object
Returns the value of attribute key_handler.
10 11 12 |
# File 'lib/sym/application.rb', line 10 def key_handler @key_handler end |
#key_source ⇒ Object
Returns the value of attribute key_source.
10 11 12 |
# File 'lib/sym/application.rb', line 10 def key_source @key_source end |
#opts ⇒ Object
Returns the value of attribute opts.
10 11 12 |
# File 'lib/sym/application.rb', line 10 def opts @opts end |
#opts_original ⇒ Object
Returns the value of attribute opts_original.
10 11 12 |
# File 'lib/sym/application.rb', line 10 def opts_original @opts_original end |
#output ⇒ Object
Returns the value of attribute output.
10 11 12 |
# File 'lib/sym/application.rb', line 10 def output @output end |
#password_cache ⇒ Object
Returns the value of attribute password_cache.
10 11 12 |
# File 'lib/sym/application.rb', line 10 def password_cache @password_cache end |
#provided_options ⇒ Object
Returns the value of attribute provided_options.
10 11 12 |
# File 'lib/sym/application.rb', line 10 def @provided_options end |
#result ⇒ Object
Returns the value of attribute result.
10 11 12 |
# File 'lib/sym/application.rb', line 10 def result @result end |
Instance Method Details
#command ⇒ Object
76 77 78 79 80 |
# File 'lib/sym/application.rb', line 76 def command @command_class ||= Sym::App::Commands.find_command_class(opts) @command ||= @command_class.new(self) if @command_class @command end |
#editor ⇒ Object
86 87 88 |
# File 'lib/sym/application.rb', line 86 def editor editors_to_try.find { |editor| File.exist?(editor) } end |
#execute ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/sym/application.rb', line 54 def execute execute! rescue ::OpenSSL::Cipher::CipherError => e { reason: 'Invalid key provided', exception: e } rescue Sym::Errors::Error => e { reason: e.class.name.gsub(/.*::/, '').underscore.humanize.downcase, exception: e } rescue TypeError => e if e. =~ /marshal/m { reason: 'Corrupt source data or invalid/corrupt key provided', exception: e } else { exception: e } end rescue StandardError => e { exception: e } end |
#execute! ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sym/application.rb', line 39 def execute! initialize_key_source unless command raise Sym::Errors::InsufficientOptionsError, " Can not determine what to do from the options: \ n " + " #{self..inspect.green.bold}\n" + "and flags #{self.provided_flags.to_s.green.bold}" end log :info, "command located is #{command.class.name.blue.bold}" self.result = command.execute.tap do |result| log :info, "result is #{result.nil? ? 'nil' : result[0..10].to_s.blue.bold }..." if opts[:trace] end end |
#log(*args) ⇒ Object
82 83 84 |
# File 'lib/sym/application.rb', line 82 def log(*args) Sym::App.log(*args, **opts) end |
#provided_flags ⇒ Object
104 105 106 107 108 |
# File 'lib/sym/application.rb', line 104 def provided_flags provided_flags = provided_flags.delete_if { |k, v| ![false, true].include?(v) } provided_flags.keys end |
#provided_safe_options ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/sym/application.rb', line 96 def .map do |k, v| k == :key && [44, 45].include?(v.size) ? [k, '[reducted]'] : [k, v] end.to_h end |
#provided_value_options ⇒ Object
110 111 112 113 114 |
# File 'lib/sym/application.rb', line 110 def provided = provided.delete_if { |k, v| [false, true].include?(v) } provided end |