Class: Jets::CLI::Base

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Api, AwsServices, Util::Logging, Util::Sure
Defined in:
lib/jets/cli/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util::Logging

#log

Methods included from AwsServices

#apigateway, #aws_options, #cfn, #codebuild, #dynamodb, #lambda_client, #logs, #s3, #s3_resource, #sns, #sqs, #ssm, #sts, #wafv2

Methods included from AwsServices::StackStatus

#output_value, #stack_exists?

Methods included from AwsServices::GlobalMemoist

included, #reset_cache!

Methods included from Api

#api, #api_key

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



10
11
12
13
# File 'lib/jets/cli/base.rb', line 10

def initialize(options = {})
  @options = options
  Jets.boot
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Class Method Details

.rescue_api_error(*methods) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jets/cli/base.rb', line 29

def rescue_api_error(*methods)
  methods = [:run] if methods.empty?
  mod = Module.new do
    methods.each do |method_name|
      define_method(method_name) do |*args, &block|
        super(*args, &block)
      rescue Jets::Api::Error => e
        warn "Jets API Error. #{e.message}".color(:red)
        log.debug e.backtrace.join("\n")
        exit 1
      end
    end
  end
  prepend mod
end

Instance Method Details

#paginate(resp) ⇒ Object



23
24
25
26
# File 'lib/jets/cli/base.rb', line 23

def paginate(resp)
  return unless resp[:total_pages] > 1
  warn "\npage #{resp[:current_page]} of #{resp[:total_pages]}"
end

#paging_paramsObject



15
16
17
18
19
20
21
# File 'lib/jets/cli/base.rb', line 15

def paging_params
  params = {}
  params[:limit] = @options[:limit] if @options[:limit]
  params[:order] = @options[:order] if @options[:order]
  params[:page] = @options[:page] if @options[:page]
  params
end