Class: Secrets::App::Commands::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/secrets/app/commands/command.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cli) ⇒ Command

Returns a new instance of Command.



36
37
38
# File 'lib/secrets/app/commands/command.rb', line 36

def initialize(cli)
  self.cli = cli
end

Instance Attribute Details

#cliObject

Returns the value of attribute cli.



34
35
36
# File 'lib/secrets/app/commands/command.rb', line 34

def cli
  @cli
end

Class Method Details

.inherited(klass) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/secrets/app/commands/command.rb', line 7

def self.inherited(klass)
  klass.instance_eval do
    @required_options = Set.new
    class << self
      def required_options(*args)
        @required_options.merge(args) if args
        @required_options
      end

      def short_name
        name.split(/::/)[-1].underscore
      end

      def options_satisfied_by?(opts_hash)
        proc = required_options.find { |option| option.is_a?(Proc) }
        return true if proc && proc.call(opts_hash)

        required_options.to_a.delete_if { |o| o.is_a?(Proc) }.all? { |o|
          o.is_a?(Array) ? o.any? { |opt| opts_hash[opt] } : opts_hash[o]
        }
      end
    end
    # Register this command with the global list.
    Secrets::App::Commands.register klass
  end
end

Instance Method Details

#keyObject



44
45
46
# File 'lib/secrets/app/commands/command.rb', line 44

def key
  @key ||= opts[:private_key]
end

#optsObject



40
41
42
# File 'lib/secrets/app/commands/command.rb', line 40

def opts
  cli.opts
end

#runObject



48
49
50
# File 'lib/secrets/app/commands/command.rb', line 48

def run
  raise Secrets::Errors::AbstractMethodCalled.new(:run)
end