Sha256: 428080ed79abeb8ac58442f88432594b0d34338faffc54d58692f698495a1d22

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

class Jets::CLI
  class Base
    extend Memoist
    include Jets::Api
    include Jets::AwsServices
    include Jets::Util::Logging
    include Jets::Util::Sure

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

    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

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

    class << self
      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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jets-6.0.5 lib/jets/cli/base.rb
jets-6.0.4 lib/jets/cli/base.rb
jets-6.0.3 lib/jets/cli/base.rb
jets-6.0.2 lib/jets/cli/base.rb