Sha256: 8688746c12883936f985126d1918d91a3241eb8c008c8e0fd678e7a34e07ac50

Contents?: true

Size: 1.25 KB

Versions: 42

Compression:

Stored size: 1.25 KB

Contents

require 'bootic_cli/store'
require 'bootic_cli/session'

module BooticCli
  module Connectivity

    DEFAULT_ENV = 'production'.freeze

    private

    def session
      @session ||= (
        store = BooticCli::Store.new(base_dir: ENV['HOME'], namespace: current_env)
        BooticCli::Session.new(store)
      )
    end

    def current_env
      ENV['ENV'] || DEFAULT_ENV
    end

    def root
      @root ||= session.client.root
    end

    def shop
      root.shops.first
    end

    def logged_in_action(&block)
      check_client_keys!
      check_access_token!
      yield
    rescue StandardError => e
      say e.message, :red
      nil
    end

    def check_access_token!
      if !session.logged_in?
        raise "No access token found! Please run `bootic login`."
      end
    end

    def check_client_keys
      has_client_keys? or say "CLI not configured yet! Please run `bootic setup`.", :magenta
    end

    def check_client_keys!
      has_client_keys? or raise "CLI not configured yet! Please run `bootic setup`."
    end

    def has_client_keys?
      if session.needs_upgrade?
        say "Old store data structure, restructuring to support multiple environments...", :cyan
        session.upgrade!
      end

      session.setup?
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
bootic_cli-1.2.0 lib/bootic_cli/connectivity.rb
bootic_cli-1.1.0 lib/bootic_cli/connectivity.rb
bootic_cli-1.0.0 lib/bootic_cli/connectivity.rb
bootic_cli-0.9.6 lib/bootic_cli/connectivity.rb
bootic_cli-0.9.5 lib/bootic_cli/connectivity.rb
bootic_cli-0.9.4 lib/bootic_cli/connectivity.rb
bootic_cli-0.9.3 lib/bootic_cli/connectivity.rb
bootic_cli-0.9.2 lib/bootic_cli/connectivity.rb
bootic_cli-0.9.1 lib/bootic_cli/connectivity.rb
bootic_cli-0.9.0 lib/bootic_cli/connectivity.rb
bootic_cli-0.8.2 lib/bootic_cli/connectivity.rb
bootic_cli-0.8.1 lib/bootic_cli/connectivity.rb
bootic_cli-0.8.0 lib/bootic_cli/connectivity.rb
bootic_cli-0.7.3 lib/bootic_cli/connectivity.rb
bootic_cli-0.7.2 lib/bootic_cli/connectivity.rb
bootic_cli-0.7.1 lib/bootic_cli/connectivity.rb
bootic_cli-0.7.0 lib/bootic_cli/connectivity.rb
bootic_cli-0.6.7 lib/bootic_cli/connectivity.rb
bootic_cli-0.6.6 lib/bootic_cli/connectivity.rb
bootic_cli-0.6.5 lib/bootic_cli/connectivity.rb