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.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 middleware && development? && !disable_middleware logger.info "Using copytuner sync middleware" middleware.use RequestSync, :cache => cache, :interval => sync_interval, :ignore_regex => sync_ignore_path_regex else logger.info "[[[Warn]]] Not useing copytuner sync middleware" unless middleware end @applied = true logger.info "Client #{VERSION} ready" logger.info "Environment Info: #{environment_info}" unless test? process_guard.start end if test? and !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 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 = 2 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 = false self.test_environments = %w(test cucumber) @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? } OPTIONS.inject(base_options) do |hash, option| hash.merge option.to_sym => send(option) end end