Class: Sym::Application
Overview
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.
-
#kernel ⇒ Object
Returns the value of attribute kernel.
-
#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_slop ⇒ Object
Returns the value of attribute opts_slop.
-
#output ⇒ Object
Returns the value of attribute output.
-
#password_cache ⇒ Object
Returns the value of attribute password_cache.
-
#result ⇒ Object
Returns the value of attribute result.
-
#stderr ⇒ Object
Returns the value of attribute stderr.
-
#stdin ⇒ Object
Returns the value of attribute stdin.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
Instance Method Summary collapse
- #command ⇒ Object
- #editor ⇒ Object
-
#execute ⇒ Object
Main action method — it looksup the command, and executes it, translating various exception conditions into meaningful error messages.
-
#initialize(opts, stdin = $stdin, stdout = $stdout, stderr = $stderr, kernel = nil) ⇒ Application
constructor
A new instance of Application.
- #process_output(result) ⇒ Object
- #provided_flags ⇒ Object
- #provided_options(**opts) ⇒ Object
- #provided_value_options ⇒ Object
Constructor Details
#initialize(opts, stdin = $stdin, stdout = $stdout, stderr = $stderr, kernel = nil) ⇒ Application
Returns a new instance of Application.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sym/application.rb', line 34 def initialize(opts, stdin = $stdin, stdout = $stdout, stderr = $stderr, kernel = nil) self.stdin = stdin self.stdout = stdout self.stderr = stderr self.kernel = kernel self.opts_slop = opts.clone self.opts = opts.is_a?(Hash) ? opts : opts.to_hash process_negated_option(opts[:negate]) if opts[:negate] process_edit_option 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.
21 22 23 |
# File 'lib/sym/application.rb', line 21 def action @action end |
#args ⇒ Object
Returns the value of attribute args.
21 22 23 |
# File 'lib/sym/application.rb', line 21 def args @args end |
#input_handler ⇒ Object
Returns the value of attribute input_handler.
21 22 23 |
# File 'lib/sym/application.rb', line 21 def input_handler @input_handler end |
#kernel ⇒ Object
Returns the value of attribute kernel.
21 22 23 |
# File 'lib/sym/application.rb', line 21 def kernel @kernel end |
#key ⇒ Object
Returns the value of attribute key.
21 22 23 |
# File 'lib/sym/application.rb', line 21 def key @key end |
#key_handler ⇒ Object
Returns the value of attribute key_handler.
21 22 23 |
# File 'lib/sym/application.rb', line 21 def key_handler @key_handler end |
#key_source ⇒ Object
Returns the value of attribute key_source.
21 22 23 |
# File 'lib/sym/application.rb', line 21 def key_source @key_source end |
#opts ⇒ Object
Returns the value of attribute opts.
21 22 23 |
# File 'lib/sym/application.rb', line 21 def opts @opts end |
#opts_slop ⇒ Object
Returns the value of attribute opts_slop.
21 22 23 |
# File 'lib/sym/application.rb', line 21 def opts_slop @opts_slop end |
#output ⇒ Object
Returns the value of attribute output.
21 22 23 |
# File 'lib/sym/application.rb', line 21 def output @output end |
#password_cache ⇒ Object
Returns the value of attribute password_cache.
21 22 23 |
# File 'lib/sym/application.rb', line 21 def password_cache @password_cache end |
#result ⇒ Object
Returns the value of attribute result.
21 22 23 |
# File 'lib/sym/application.rb', line 21 def result @result end |
#stderr ⇒ Object
Returns the value of attribute stderr.
21 22 23 |
# File 'lib/sym/application.rb', line 21 def stderr @stderr end |
#stdin ⇒ Object
Returns the value of attribute stdin.
21 22 23 |
# File 'lib/sym/application.rb', line 21 def stdin @stdin end |
#stdout ⇒ Object
Returns the value of attribute stdout.
21 22 23 |
# File 'lib/sym/application.rb', line 21 def stdout @stdout end |
Instance Method Details
#command ⇒ Object
80 81 82 83 84 |
# File 'lib/sym/application.rb', line 80 def command @command_class ||= Sym::App::Commands.find_command_class(opts) @command ||= @command_class.new(self) if @command_class @command end |
#editor ⇒ Object
112 113 114 |
# File 'lib/sym/application.rb', line 112 def editor editors_to_try.compact.find { |editor| File.exist?(editor) } end |
#execute ⇒ Object
Main action method — it looksup the command, and executes it, translating various exception conditions into meaningful error messages.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/sym/application.rb', line 57 def execute process_output(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 |
#process_output(result) ⇒ Object
116 117 118 119 |
# File 'lib/sym/application.rb', line 116 def process_output(result) self.output.call(result) unless result.is_a?(Hash) result end |
#provided_flags ⇒ Object
86 87 88 89 90 |
# File 'lib/sym/application.rb', line 86 def provided_flags provided_flags = provided_flags.delete_if { |k, v| ![false, true].include?(v) } provided_flags.keys end |
#provided_options(**opts) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/sym/application.rb', line 98 def (**opts) provided_opts = self.opts.clone provided_opts.delete_if { |k, v| !v } if opts[:safe] .map do |k, v| k == :key && [44, 45].include?(v.size) ? [k, '[reducted]'] : [k, v] end.to_h else provided_opts end end |
#provided_value_options ⇒ Object
92 93 94 95 96 |
# File 'lib/sym/application.rb', line 92 def provided = (safe: true) provided.delete_if { |k, v| [false, true].include?(v) } provided end |