Class: CopyTunerClient::Configuration
- Inherits:
-
Object
- Object
- CopyTunerClient::Configuration
- Defined in:
- lib/copy_tuner_client/configuration.rb
Overview
Used to set up and modify settings for the client.
Constant Summary collapse
- OPTIONS =
These options will be present in the Hash returned by #to_hash.
%i[api_key development_environments environment_name host http_open_timeout http_read_timeout client_name client_url client_version port protocol proxy_host proxy_pass proxy_port proxy_user secure polling_delay sync_interval sync_interval_staging sync_ignore_path_regex logger framework middleware disable_middleware disable_test_translation ca_file exclude_key_regexp s3_host locales ignored_keys ignored_key_handler download_cache_dir].freeze
Instance Attribute Summary collapse
-
#api_key ⇒ String
The API key for your project, found on the project edit form.
-
#ca_file ⇒ String
The path to a root certificate file used to verify ssl sessions.
-
#cache ⇒ Cache
Instance used internally to synchronize changes.
-
#client ⇒ Client
Instance used to communicate with a CopyTuner Server.
-
#client_name ⇒ String
The name of the client library being used to send notifications (defaults to CopyTuner Client).
-
#client_url ⇒ String
The url of the client library being used.
-
#client_version ⇒ String
The version of the client library being used to send notifications (such as
1.0.2). -
#development_environments ⇒ Array<String>
A list of environments in which content should be editable.
-
#disable_copyray_comment_injection ⇒ Boolean
To disable Copyray comment injection, set true.
-
#disable_middleware ⇒ Boolean
Disable middleware setting.
-
#disable_test_translation ⇒ Boolean
Disable download translation for test enviroment.
-
#download_cache_dir ⇒ Pathname
The directory to cache downloaded files.
-
#environment_name ⇒ String
The name of the environment the application is running in.
-
#exclude_key_regexp ⇒ Regexp
Regular expression to exclude keys.
-
#framework ⇒ String, NilClass
The framework notifications are being sent from, if any (such as Rails 2.3.9).
-
#host ⇒ String
The host to connect to (defaults to
copy-tuner.com). -
#html_escape ⇒ Boolean
Html escape.
-
#http_open_timeout ⇒ Fixnum
The HTTP open timeout in seconds (defaults to
2). -
#http_read_timeout ⇒ Fixnum
The HTTP read timeout in seconds (defaults to
5). - #ignored_key_handler ⇒ Proc
-
#ignored_keys ⇒ Array<String>
A list of ignored keys.
-
#inline_translation ⇒ Boolean
To enable inline-translation-mode, set true.
-
#locales ⇒ Array<Symbol>
Restrict blurb locales to upload.
-
#logger ⇒ Logger
Where to log messages.
-
#middleware ⇒ Object
The middleware stack, if any, which should respond to
use. -
#middleware_position ⇒ Object
OtherMiddleware or OtherMiddleware.
-
#poller ⇒ Object
Returns the value of attribute poller.
-
#polling_delay ⇒ Integer
The time, in seconds, in between each sync to the server.
-
#port ⇒ Fixnum
The port on which your CopyTuner server runs (defaults to
443for secure connections,80for insecure connections). -
#project_id ⇒ Integer
The project id.
-
#proxy_host ⇒ String, NilClass
The hostname of your proxy server (if using a proxy).
-
#proxy_pass ⇒ String, NilClass
The password to use when logging into your proxy server (if using a proxy).
-
#proxy_port ⇒ String, Fixnum
The port of your proxy server (if using a proxy).
-
#proxy_user ⇒ String, NilClass
The username to use when logging into your proxy server (if using a proxy).
-
#s3_host ⇒ String
The S3 host to connect to (defaults to
copy-tuner-us.s3.amazonaws.com). -
#secure ⇒ Boolean
(also: #secure?)
truefor https connections,falsefor http connections. -
#sync_ignore_path_regex ⇒ Regex
Format ignore hook middleware sync.
-
#sync_interval ⇒ Object
Sync interval for Rack Middleware.
-
#sync_interval_staging ⇒ Integer
The time, in seconds, in between each sync to the server in development.
-
#test_environments ⇒ Array<String>
A list of environments in which the server should not be contacted.
-
#upload_disabled_environments ⇒ Array<String>
A list of environments in which the server should not be upload.
Instance Method Summary collapse
-
#[](option) ⇒ Object
Allows config options to be read like a hash.
-
#applied? ⇒ Boolean
Determines if the configuration has been applied (internal).
-
#apply ⇒ Object
Applies the configuration (internal).
-
#development? ⇒ Boolean
Determines if the content will be editable.
- #enable_middleware? ⇒ Boolean
-
#environment_info ⇒ String
For logging/debugging (internal).
-
#initialize ⇒ Configuration
constructor
Instantiated from configure.
-
#merge(hash) ⇒ Hash
Returns a hash of all configurable options merged with
hash. -
#project_url ⇒ String
Current project url by api_key.
-
#protocol ⇒ String
The protocol that should be used when generating URLs to CopyTuner.
-
#public? ⇒ Boolean
Determines if the published or draft content will be used environment,
trueotherwise. -
#test? ⇒ Boolean
Determines if the content will fetched from the server.
-
#to_hash ⇒ Hash
Returns a hash of all configurable options.
- #upload_disabled? ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Instantiated from CopyTunerClient.configure. Sets defaults.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/copy_tuner_client/configuration.rb', line 149 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.sg-apps.com' # NOTE: cloudfront host self.disable_copyray_comment_injection = false self.html_escape = true self.ignored_keys = [] self.ignored_key_handler = ->(e) { raise e } self.project_id = nil self.download_cache_dir = Pathname.new(Dir.pwd).join('tmp', 'cache', 'copy_tuner_client') @applied = false end |
Instance Attribute Details
#api_key ⇒ String
Returns The API key for your project, found on the project edit form.
25 26 27 |
# File 'lib/copy_tuner_client/configuration.rb', line 25 def api_key @api_key end |
#ca_file ⇒ String
Returns the path to a root certificate file used to verify ssl sessions. Default’s to the root certificate file for copy-tuner.com.
106 107 108 |
# File 'lib/copy_tuner_client/configuration.rb', line 106 def ca_file @ca_file end |
#cache ⇒ Cache
Returns instance used internally to synchronize changes.
109 110 111 |
# File 'lib/copy_tuner_client/configuration.rb', line 109 def cache @cache end |
#client ⇒ Client
Returns instance used to communicate with a CopyTuner Server.
112 113 114 |
# File 'lib/copy_tuner_client/configuration.rb', line 112 def client @client end |
#client_name ⇒ String
Returns The name of the client library being used to send notifications (defaults to CopyTuner Client).
67 68 69 |
# File 'lib/copy_tuner_client/configuration.rb', line 67 def client_name @client_name end |
#client_url ⇒ String
Returns The url of the client library being used.
76 77 78 |
# File 'lib/copy_tuner_client/configuration.rb', line 76 def client_url @client_url end |
#client_version ⇒ String
Returns The version of the client library being used to send notifications (such as 1.0.2).
73 74 75 |
# File 'lib/copy_tuner_client/configuration.rb', line 73 def client_version @client_version end |
#development_environments ⇒ Array<String>
Returns A list of environments in which content should be editable.
55 56 57 |
# File 'lib/copy_tuner_client/configuration.rb', line 55 def development_environments @development_environments end |
#disable_copyray_comment_injection ⇒ Boolean
Returns To disable Copyray comment injection, set true.
126 127 128 |
# File 'lib/copy_tuner_client/configuration.rb', line 126 def disable_copyray_comment_injection @disable_copyray_comment_injection end |
#disable_middleware ⇒ Boolean
Returns disable middleware setting.
97 98 99 |
# File 'lib/copy_tuner_client/configuration.rb', line 97 def disable_middleware @disable_middleware end |
#disable_test_translation ⇒ Boolean
Returns disable download translation for test enviroment.
103 104 105 |
# File 'lib/copy_tuner_client/configuration.rb', line 103 def disable_test_translation @disable_test_translation end |
#download_cache_dir ⇒ Pathname
Returns The directory to cache downloaded files.
144 145 146 |
# File 'lib/copy_tuner_client/configuration.rb', line 144 def download_cache_dir @download_cache_dir end |
#environment_name ⇒ String
Returns The name of the environment the application is running in.
64 65 66 |
# File 'lib/copy_tuner_client/configuration.rb', line 64 def environment_name @environment_name end |
#exclude_key_regexp ⇒ Regexp
Returns Regular expression to exclude keys.
120 121 122 |
# File 'lib/copy_tuner_client/configuration.rb', line 120 def exclude_key_regexp @exclude_key_regexp end |
#framework ⇒ String, NilClass
Returns The framework notifications are being sent from, if any (such as Rails 2.3.9).
70 71 72 |
# File 'lib/copy_tuner_client/configuration.rb', line 70 def framework @framework end |
#host ⇒ String
Returns The host to connect to (defaults to copy-tuner.com).
28 29 30 |
# File 'lib/copy_tuner_client/configuration.rb', line 28 def host @host end |
#html_escape ⇒ Boolean
Returns Html escape.
132 133 134 |
# File 'lib/copy_tuner_client/configuration.rb', line 132 def html_escape @html_escape end |
#http_open_timeout ⇒ Fixnum
Returns The HTTP open timeout in seconds (defaults to 2).
37 38 39 |
# File 'lib/copy_tuner_client/configuration.rb', line 37 def http_open_timeout @http_open_timeout end |
#http_read_timeout ⇒ Fixnum
Returns The HTTP read timeout in seconds (defaults to 5).
40 41 42 |
# File 'lib/copy_tuner_client/configuration.rb', line 40 def http_read_timeout @http_read_timeout end |
#ignored_key_handler ⇒ Proc
138 139 140 |
# File 'lib/copy_tuner_client/configuration.rb', line 138 def ignored_key_handler @ignored_key_handler end |
#ignored_keys ⇒ Array<String>
Returns A list of ignored keys.
135 136 137 |
# File 'lib/copy_tuner_client/configuration.rb', line 135 def ignored_keys @ignored_keys end |
#inline_translation ⇒ Boolean
Returns To enable inline-translation-mode, set true.
117 118 119 |
# File 'lib/copy_tuner_client/configuration.rb', line 117 def inline_translation @inline_translation end |
#locales ⇒ Array<Symbol>
Returns Restrict blurb locales to upload.
129 130 131 |
# File 'lib/copy_tuner_client/configuration.rb', line 129 def locales @locales end |
#logger ⇒ Logger
Returns Where to log messages. Must respond to same interface as Logger.
91 92 93 |
# File 'lib/copy_tuner_client/configuration.rb', line 91 def logger @logger end |
#middleware ⇒ Object
Returns the middleware stack, if any, which should respond to use.
94 95 96 |
# File 'lib/copy_tuner_client/configuration.rb', line 94 def middleware @middleware end |
#middleware_position ⇒ Object
OtherMiddleware or OtherMiddleware
100 101 102 |
# File 'lib/copy_tuner_client/configuration.rb', line 100 def middleware_position @middleware_position end |
#poller ⇒ Object
Returns the value of attribute poller.
114 115 116 |
# File 'lib/copy_tuner_client/configuration.rb', line 114 def poller @poller end |
#polling_delay ⇒ Integer
Returns The time, in seconds, in between each sync to the server. Defaults to 300.
79 80 81 |
# File 'lib/copy_tuner_client/configuration.rb', line 79 def polling_delay @polling_delay end |
#port ⇒ Fixnum
Returns The port on which your CopyTuner server runs (defaults to 443 for secure connections, 80 for insecure connections).
31 32 33 |
# File 'lib/copy_tuner_client/configuration.rb', line 31 def port @port end |
#project_id ⇒ Integer
Returns The project id.
141 142 143 |
# File 'lib/copy_tuner_client/configuration.rb', line 141 def project_id @project_id end |
#proxy_host ⇒ String, NilClass
Returns The hostname of your proxy server (if using a proxy).
43 44 45 |
# File 'lib/copy_tuner_client/configuration.rb', line 43 def proxy_host @proxy_host end |
#proxy_pass ⇒ String, NilClass
Returns The password to use when logging into your proxy server (if using a proxy).
52 53 54 |
# File 'lib/copy_tuner_client/configuration.rb', line 52 def proxy_pass @proxy_pass end |
#proxy_port ⇒ String, Fixnum
Returns The port of your proxy server (if using a proxy).
46 47 48 |
# File 'lib/copy_tuner_client/configuration.rb', line 46 def proxy_port @proxy_port end |
#proxy_user ⇒ String, NilClass
Returns The username to use when logging into your proxy server (if using a proxy).
49 50 51 |
# File 'lib/copy_tuner_client/configuration.rb', line 49 def proxy_user @proxy_user end |
#s3_host ⇒ String
Returns The S3 host to connect to (defaults to copy-tuner-us.s3.amazonaws.com).
123 124 125 |
# File 'lib/copy_tuner_client/configuration.rb', line 123 def s3_host @s3_host end |
#secure ⇒ Boolean Also known as: secure?
Returns true for https connections, false for http connections.
34 35 36 |
# File 'lib/copy_tuner_client/configuration.rb', line 34 def secure @secure end |
#sync_ignore_path_regex ⇒ Regex
Returns Format ignore hook middleware sync.
88 89 90 |
# File 'lib/copy_tuner_client/configuration.rb', line 88 def sync_ignore_path_regex @sync_ignore_path_regex end |
#sync_interval ⇒ Object
Sync interval for Rack Middleware
82 83 84 |
# File 'lib/copy_tuner_client/configuration.rb', line 82 def sync_interval @sync_interval end |
#sync_interval_staging ⇒ Integer
Returns The time, in seconds, in between each sync to the server in development. Defaults to 60.
85 86 87 |
# File 'lib/copy_tuner_client/configuration.rb', line 85 def sync_interval_staging @sync_interval_staging end |
#test_environments ⇒ Array<String>
Returns A list of environments in which the server should not be contacted.
58 59 60 |
# File 'lib/copy_tuner_client/configuration.rb', line 58 def test_environments @test_environments end |
#upload_disabled_environments ⇒ Array<String>
Returns A list of environments in which the server should not be upload.
61 62 63 |
# File 'lib/copy_tuner_client/configuration.rb', line 61 def upload_disabled_environments @upload_disabled_environments end |
Instance Method Details
#[](option) ⇒ Object
Allows config options to be read like a hash
179 180 181 |
# File 'lib/copy_tuner_client/configuration.rb', line 179 def [](option) send(option) end |
#applied? ⇒ Boolean
Determines if the configuration has been applied (internal)
230 231 232 |
# File 'lib/copy_tuner_client/configuration.rb', line 230 def applied? @applied end |
#apply ⇒ Object
Applies the configuration (internal).
Called automatically when CopyTunerClient.configure is called in the application.
This creates the I18nBackend and puts them together.
When #test? returns false, the poller will be started.
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/copy_tuner_client/configuration.rb', line 241 def apply self.locales ||= self.locales = if defined?(::Rails) ::Rails.application.config.i18n.available_locales.presence || Array(::Rails.application.config.i18n.default_locale) else [:en] 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' = { poller: @poller, 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, middleware.insert_before middleware_position[:before], CopyTunerClient::CopyrayMiddleware elsif middleware_position.is_a?(Hash) && middleware_position[:after] middleware.insert_after middleware_position[:after], RequestSync, middleware.insert_after middleware_position[:after], CopyTunerClient::CopyrayMiddleware else middleware.use RequestSync, 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 unless test? && disable_test_translation logger.info 'Download translation now' cache.download end end |
#development? ⇒ Boolean
Determines if the content will be editable
210 211 212 |
# File 'lib/copy_tuner_client/configuration.rb', line 210 def development? development_environments.include? environment_name end |
#enable_middleware? ⇒ Boolean
214 215 216 |
# File 'lib/copy_tuner_client/configuration.rb', line 214 def enable_middleware? middleware && development? && !disable_middleware end |
#environment_info ⇒ String
For logging/debugging (internal).
302 303 304 305 |
# File 'lib/copy_tuner_client/configuration.rb', line 302 def environment_info parts = ["Ruby: #{RUBY_VERSION}", framework, "Env: #{environment_name}"] parts.compact.map { |part| "[#{part}]" }.join(' ') end |
#merge(hash) ⇒ Hash
Returns a hash of all configurable options merged with hash
197 198 199 |
# File 'lib/copy_tuner_client/configuration.rb', line 197 def merge(hash) to_hash.merge hash end |
#project_url ⇒ String
Returns current project url by api_key.
330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/copy_tuner_client/configuration.rb', line 330 def project_url path = if project_id "/projects/#{project_id}" else ActiveSupport::Deprecation.new.warn('Please set project_id.') "/projects/#{api_key}" end URI::Generic.build(scheme: self.protocol, host: self.host, port: self.port.to_i, path:).to_s end |
#protocol ⇒ String
The protocol that should be used when generating URLs to CopyTuner.
292 293 294 295 296 297 298 |
# File 'lib/copy_tuner_client/configuration.rb', line 292 def protocol if secure? 'https' else 'http' end end |
#public? ⇒ Boolean
Determines if the published or draft content will be used environment, true otherwise.
204 205 206 |
# File 'lib/copy_tuner_client/configuration.rb', line 204 def public? !(development_environments + test_environments).include?(environment_name) end |
#test? ⇒ Boolean
Determines if the content will fetched from the server
220 221 222 |
# File 'lib/copy_tuner_client/configuration.rb', line 220 def test? test_environments.include?(environment_name) end |
#to_hash ⇒ Hash
Returns a hash of all configurable options
185 186 187 188 189 190 191 |
# File 'lib/copy_tuner_client/configuration.rb', line 185 def to_hash = { public: public?, upload_disabled: upload_disabled? } OPTIONS.inject() do |hash, option| hash.merge option.to_sym => send(option) end end |
#upload_disabled? ⇒ Boolean
224 225 226 |
# File 'lib/copy_tuner_client/configuration.rb', line 224 def upload_disabled? upload_disabled_environments.include?(environment_name) end |