Sha256: 01db3465f9f4fdce3edcf2cd2d3b820a7137e44e461fec0fd4f32e8539916678

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

require 'morale/storage'
require 'morale/platform'

module Morale
  module ConnectionStore
    include Morale::Storage
    include Morale::Platform
    
    def base_url
      if @base_url.nil?
        @base_url = read_connection
        if @base_url.nil?
          @base_url = default_base_url
          self.write_connection
        end
      end
      @base_url
    end
    
    def base_url=(value)
      @base_url = value
      self.write_connection
    end
    
    def location
      ENV['CONNECTION_LOCATION'] || default_location
    end
    
    def location=(value)
      ENV['CONNECTION_LOCATION'] = value
    end
    
    def default_location
      "#{home_directory}/.morale/connection"
    end
    
    def delete_connection
      self.delete
      @base_url = nil
    end
    
    def read_connection
      connection = self.read
      connection.split("\n")[0] if connection
    end
    
    def write_connection
      self.write self.base_url
    end
    
    private
    
    def default_base_url
      ENV['DEFAULT_BASE_URL'] || "teammorale.com"
    end
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
morale-client-1.0.3 lib/morale/connection_store.rb
morale-client-1.0.1 lib/morale/connection_store.rb