module Esi

The main Esi Module @!attribute [w] api_version

@return [Symbol] the Esi Api version used by the gem

@!attribute [w] logger

@return [Logger] the logger class for the gem

The Esi generator module @private

Constants

DEFAULT_CONFIG

The default Esi gem configuration @return [Hash{Symbol => Symbol|String|Fixnum|Object|Array}] the default configuration

SCOPES

Default ESI access scopes @return [Array<String>] the default scopes

VERSION

Attributes

api_version[W]
cache[W]
config[W]
logger[W]

Public Class Methods

api_version() click to toggle source

The Esi Api version to interface with @return [Symbol] the esi api version

# File lib/esi.rb, line 123
def api_version
  @api_version || :latest
end
cache() click to toggle source

The Esi cache class instance @return [ActiveSupport::Cache::Store] an instance of cache

# File lib/esi.rb, line 113
def cache
  if Esi.config.cache.nil?
    @cache ||= ActiveSupport::Cache::NullStore.new
  else
    Esi.config.cache
  end
end
client() click to toggle source

The current Esi client @return [Esi::Client] the current client

# File lib/esi.rb, line 140
def client
  @client ||= Client.current
end
config() click to toggle source

The Esi Configuration @return [OpenStruct] the configuration object

# File lib/esi.rb, line 99
def config
  @config ||= OpenStruct.new(DEFAULT_CONFIG)
end
generate_url(path, params = {}) click to toggle source

Generate an Esi url for a given path @param [String] path the path to generate an esi url for @param [Hash{Symbol => String|Fixnum}] params the params for the url query @return [String] the generated url

# File lib/esi.rb, line 131
def generate_url(path, params = {})
  url = url_for_path(path)
  uri = Addressable::URI.parse(url)
  uri.query_values = { datasource: config.datasource }.merge(params.to_h)
  uri.to_s
end
logger() click to toggle source

The Esi logger class instance @return [MyLoggerInstance|Logger] an instance of the logger class

# File lib/esi.rb, line 105
def logger
  @logger ||= Esi.config.logger || Logger.new(Esi.config.log_target).tap do |l|
    l.level = Logger.const_get(Esi.config.log_level.upcase)
  end
end

Private Class Methods

url_for_path(path) click to toggle source
# File lib/esi.rb, line 146
def url_for_path(path)
  path = path[1..-1] if path.start_with?('/')
  path += '/' unless path.end_with?('/')
  [config.api_host, config.api_version, path].join('/')
end