class CopyTunerClient::Configuration
Used to set up and modify settings for the client.
def [](option)
-
(Object)
- the given attribute
Parameters:
-
option
(Symbol
) -- Key for a given attribute
def [](option) send(option) end
def applied?
-
(Boolean)
- Returns +true+ if applied, +false+ otherwise.
def applied? @applied end
def apply
This creates the {I18nBackend} and puts them together.
Called automatically when {CopyTunerClient.configure} is called in the application.
Applies the configuration (internal).
def apply self.locales ||= begin if defined?(::Rails) self.locales = ::Rails.application.config.i18n.available_locales.presence || Array(::Rails.application.config.i18n.default_locale) else self.locales = [:en] end end self.client ||= Client.new(to_hash) self.cache ||= Cache.new(client, to_hash) @poller = Poller.new(cache, to_hash) process_guard = ProcessGuard.new(cache, @poller, to_hash) I18n.backend = I18nBackend.new(cache) if enable_middleware? logger.info "Using copytuner sync middleware" request_sync_options = {:poller => @poller, :cache => cache, :interval => sync_interval, :ignore_regex => sync_ignore_path_regex} if middleware_position.is_a?(Hash) && middleware_position[:before] middleware.insert_before middleware_position[:before], RequestSync, request_sync_options middleware.insert_before middleware_position[:before], CopyTunerClient::CopyrayMiddleware elsif middleware_position.is_a?(Hash) && middleware_position[:after] middleware.insert_after middleware_position[:after], RequestSync, request_sync_options middleware.insert_after middleware_position[:after], CopyTunerClient::CopyrayMiddleware else middleware.use RequestSync, request_sync_options middleware.use CopyTunerClient::CopyrayMiddleware end else logger.info "[[[Warn]]] Not using copytuner sync middleware" unless middleware end @applied = true logger.info "Client #{VERSION} ready (s3_download)" logger.info "Environment Info: #{environment_info}" logger.info "Available locales: #{self.locales.join(' ')}" unless test? process_guard.start end if !(test? && disable_test_translation) logger.info "Download translation now" cache.download end end
def default_port
def default_port if secure? 443 else 80 end end
def development?
-
(Boolean)
- Returns +true+ if in a development environment, +false+ otherwise.
def development? development_environments.include? environment_name end
def enable_middleware?
def enable_middleware? middleware && development? && !disable_middleware end
def environment_info
-
(String)
- a description of the environment in which this configuration was built.
def environment_info parts = ["Ruby: #{RUBY_VERSION}", framework, "Env: #{environment_name}"] parts.compact.map { |part| "[#{part}]" }.join(" ") end
def initialize
def initialize self.client_name = 'CopyTuner Client' self.client_url = 'https://rubygems.org/gems/copy_tuner_client' self.client_version = VERSION self.development_environments = %w(development staging) self.host = 'copy-tuner.com' self.http_open_timeout = 5 self.http_read_timeout = 5 self.logger = Logger.new($stdout) self.polling_delay = 300 self.sync_interval = 60 self.sync_interval_staging = 0 self.secure = true self.test_environments = %w(test cucumber) self.upload_disabled_environments = %w[production staging] self.s3_host = 'copy-tuner-data-prod.s3.amazonaws.com' self.disable_copyray_comment_injection = false self.html_escape = false self.ignored_keys = [] self.ignored_key_handler = -> (e) { raise e } @applied = false end
def logger=(original_logger)
-
original_logger
(Logger
) -- the upstream logger to use, which must respond to the standard +Logger+ severity methods.
def logger=(original_logger) @logger = PrefixedLogger.new("** [CopyTuner]", original_logger) end
def merge(hash)
-
(Hash)
- the merged configuration hash
Parameters:
-
hash
(Hash
) -- A set of configuration options that will take precedence over the defaults
def merge(hash) to_hash.merge hash end
def port
def port @port || default_port end
def project_url
-
(String)
- current project url by api_key
def project_url URI::Generic.build(:scheme => self.protocol, :host => self.host, :port => self.port.to_i, :path => "/projects/#{self.api_key}").to_s end
def protocol
-
(String)
- +https+ if {#secure?} returns +true+, +http+ otherwise.
def protocol if secure? 'https' else 'http' end end
def public?
-
(Boolean)
- Returns +false+ if in a development or test
def public? !(development_environments + test_environments).include?(environment_name) end
def sync_interval
def sync_interval if environment_name == "staging" @sync_interval_staging else @sync_interval end end
def test?
-
(Boolean)
- Returns +true+ if in a test environment, +false+ otherwise.
def test? test_environments.include?(environment_name) end
def to_hash
-
(Hash)
- configuration attributes
def to_hash base_options = { public: public?, upload_disabled: upload_disabled? } OPTIONS.inject(base_options) do |hash, option| hash.merge option.to_sym => send(option) end end
def upload_disabled?
def upload_disabled? upload_disabled_environments.include?(environment_name) end