Class: Tabry::CLI::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/tabry/cli/base.rb

Direct Known Subclasses

AllInOne::AllInOneBase

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flags, args, named_args, internals) ⇒ Base

Returns a new instance of Base.



11
12
13
14
15
# File 'lib/tabry/cli/base.rb', line 11

def initialize(flags, args, named_args, internals)
  @args = ArgProxy.new(args, named_args)
  @flags = FlagProxy.new(flags)
  @internals = internals
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



9
10
11
# File 'lib/tabry/cli/base.rb', line 9

def args
  @args
end

#flagsObject (readonly)

Returns the value of attribute flags.



9
10
11
# File 'lib/tabry/cli/base.rb', line 9

def flags
  @flags
end

#internalsObject (readonly)

Returns the value of attribute internals.



9
10
11
# File 'lib/tabry/cli/base.rb', line 9

def internals
  @internals
end

Class Method Details

.after_action(*method_names, only: nil, except: nil, &blk) ⇒ Object



24
25
26
27
28
# File 'lib/tabry/cli/base.rb', line 24

def self.after_action(*method_names, only: nil, except: nil, &blk)
  [*method_names, blk].compact.each do |met|
    (@after_actions ||= []) << [met, { only: only, except: except }]
  end
end

.before_action(*method_names, only: nil, except: nil, &blk) ⇒ Object



30
31
32
33
34
# File 'lib/tabry/cli/base.rb', line 30

def self.before_action(*method_names, only: nil, except: nil, &blk)
  [*method_names, blk].compact.each do |met|
    (@before_actions ||= []) << [met, { only: only, except: except }]
  end
end

.sub_route(*prefixes, to:, **opts) ⇒ Object



17
18
19
20
21
22
# File 'lib/tabry/cli/base.rb', line 17

def self.sub_route(*prefixes, to:, **opts)
  prefixes.map(&:to_s).each do |prefix|
    (@sub_route_clis ||= {})[prefix] = to
    (@sub_route_clis_opts ||= {})[prefix] = opts
  end
end