Class: CopycopterClient::Configuration
- Inherits:
-
Object
- Object
- CopycopterClient::Configuration
- Defined in:
- lib/copycopter_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.
[: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, :logger, :framework, :middleware, :ca_file].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 Copycopter Server.
-
#client_name ⇒ String
The name of the client library being used to send notifications (defaults to Copycopter 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.
-
#environment_name ⇒ String
The name of the environment the application is running in.
-
#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
copycopter.com
). -
#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
). -
#logger ⇒ Logger
Where to log messages.
-
#middleware ⇒ Object
The middleware stack, if any, which should respond to
use
. -
#polling_delay ⇒ Integer
The time, in seconds, in between each sync to the server.
-
#port ⇒ Fixnum
The port on which your Copycopter server runs (defaults to
443
for secure connections,80
for insecure connections). -
#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).
-
#secure ⇒ Boolean
(also: #secure?)
true
for https connections,false
for http connections. -
#test_environments ⇒ Array<String>
A list of environments in which the server should not be contacted.
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.
-
#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
. -
#protocol ⇒ String
The protocol that should be used when generating URLs to Copycopter.
-
#public? ⇒ Boolean
Determines if the published or draft content will be used environment,
true
otherwise. -
#test? ⇒ Boolean
Determines if the content will fetched from the server.
-
#to_hash ⇒ Hash
Returns a hash of all configurable options.
Constructor Details
#initialize ⇒ Configuration
Instantiated from CopycopterClient.configure. Sets defaults.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/copycopter_client/configuration.rb', line 93 def initialize self.client_name = 'Copycopter Client' self.client_url = 'https://rubygems.org/gems/copycopter_client' self.client_version = VERSION self.development_environments = %w(development staging) self.host = 'copycopter.com' self.http_open_timeout = 2 self.http_read_timeout = 5 self.logger = Logger.new($stdout) self.polling_delay = 300 self.secure = false self.test_environments = %w(test cucumber) @applied = false end |
Instance Attribute Details
#api_key ⇒ String
Returns The API key for your project, found on the project edit form.
22 23 24 |
# File 'lib/copycopter_client/configuration.rb', line 22 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 copycopter.com.
82 83 84 |
# File 'lib/copycopter_client/configuration.rb', line 82 def ca_file @ca_file end |
#cache ⇒ Cache
Returns instance used internally to synchronize changes.
85 86 87 |
# File 'lib/copycopter_client/configuration.rb', line 85 def cache @cache end |
#client ⇒ Client
Returns instance used to communicate with a Copycopter Server.
88 89 90 |
# File 'lib/copycopter_client/configuration.rb', line 88 def client @client end |
#client_name ⇒ String
Returns The name of the client library being used to send notifications (defaults to Copycopter Client).
61 62 63 |
# File 'lib/copycopter_client/configuration.rb', line 61 def client_name @client_name end |
#client_url ⇒ String
Returns The url of the client library being used.
70 71 72 |
# File 'lib/copycopter_client/configuration.rb', line 70 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
).
67 68 69 |
# File 'lib/copycopter_client/configuration.rb', line 67 def client_version @client_version end |
#development_environments ⇒ Array<String>
Returns A list of environments in which content should be editable.
52 53 54 |
# File 'lib/copycopter_client/configuration.rb', line 52 def development_environments @development_environments end |
#environment_name ⇒ String
Returns The name of the environment the application is running in.
58 59 60 |
# File 'lib/copycopter_client/configuration.rb', line 58 def environment_name @environment_name end |
#framework ⇒ String, NilClass
Returns The framework notifications are being sent from, if any (such as Rails 2.3.9).
64 65 66 |
# File 'lib/copycopter_client/configuration.rb', line 64 def framework @framework end |
#host ⇒ String
Returns The host to connect to (defaults to copycopter.com
).
25 26 27 |
# File 'lib/copycopter_client/configuration.rb', line 25 def host @host end |
#http_open_timeout ⇒ Fixnum
Returns The HTTP open timeout in seconds (defaults to 2
).
34 35 36 |
# File 'lib/copycopter_client/configuration.rb', line 34 def http_open_timeout @http_open_timeout end |
#http_read_timeout ⇒ Fixnum
Returns The HTTP read timeout in seconds (defaults to 5
).
37 38 39 |
# File 'lib/copycopter_client/configuration.rb', line 37 def http_read_timeout @http_read_timeout end |
#logger ⇒ Logger
Returns Where to log messages. Must respond to same interface as Logger.
76 77 78 |
# File 'lib/copycopter_client/configuration.rb', line 76 def logger @logger end |
#middleware ⇒ Object
Returns the middleware stack, if any, which should respond to use
.
79 80 81 |
# File 'lib/copycopter_client/configuration.rb', line 79 def middleware @middleware end |
#polling_delay ⇒ Integer
Returns The time, in seconds, in between each sync to the server. Defaults to 300
.
73 74 75 |
# File 'lib/copycopter_client/configuration.rb', line 73 def polling_delay @polling_delay end |
#port ⇒ Fixnum
Returns The port on which your Copycopter server runs (defaults to 443
for secure connections, 80
for insecure connections).
28 29 30 |
# File 'lib/copycopter_client/configuration.rb', line 28 def port @port end |
#proxy_host ⇒ String, NilClass
Returns The hostname of your proxy server (if using a proxy).
40 41 42 |
# File 'lib/copycopter_client/configuration.rb', line 40 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).
49 50 51 |
# File 'lib/copycopter_client/configuration.rb', line 49 def proxy_pass @proxy_pass end |
#proxy_port ⇒ String, Fixnum
Returns The port of your proxy server (if using a proxy).
43 44 45 |
# File 'lib/copycopter_client/configuration.rb', line 43 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).
46 47 48 |
# File 'lib/copycopter_client/configuration.rb', line 46 def proxy_user @proxy_user end |
#secure ⇒ Boolean Also known as: secure?
Returns true
for https connections, false
for http connections.
31 32 33 |
# File 'lib/copycopter_client/configuration.rb', line 31 def secure @secure end |
#test_environments ⇒ Array<String>
Returns A list of environments in which the server should not be contacted.
55 56 57 |
# File 'lib/copycopter_client/configuration.rb', line 55 def test_environments @test_environments end |
Instance Method Details
#[](option) ⇒ Object
Allows config options to be read like a hash
112 113 114 |
# File 'lib/copycopter_client/configuration.rb', line 112 def [](option) send(option) end |
#applied? ⇒ Boolean
Determines if the configuration has been applied (internal)
155 156 157 |
# File 'lib/copycopter_client/configuration.rb', line 155 def applied? @applied end |
#apply ⇒ Object
Applies the configuration (internal).
Called automatically when CopycopterClient.configure is called in the application.
This creates the I18nBackend and puts them together.
When #test? returns false
, the poller will be started.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/copycopter_client/configuration.rb', line 166 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? middleware.use RequestSync, :cache => cache end @applied = true logger.info "Client #{VERSION} ready" logger.info "Environment Info: #{environment_info}" unless test? process_guard.start end end |
#development? ⇒ Boolean
Determines if the content will be editable
143 144 145 |
# File 'lib/copycopter_client/configuration.rb', line 143 def development? development_environments.include? environment_name end |
#environment_info ⇒ String
For logging/debugging (internal).
202 203 204 205 |
# File 'lib/copycopter_client/configuration.rb', line 202 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
130 131 132 |
# File 'lib/copycopter_client/configuration.rb', line 130 def merge(hash) to_hash.merge hash end |
#protocol ⇒ String
The protocol that should be used when generating URLs to Copycopter.
192 193 194 195 196 197 198 |
# File 'lib/copycopter_client/configuration.rb', line 192 def protocol if secure? 'https' else 'http' end end |
#public? ⇒ Boolean
Determines if the published or draft content will be used environment, true
otherwise.
137 138 139 |
# File 'lib/copycopter_client/configuration.rb', line 137 def public? !(development_environments + test_environments).include?(environment_name) end |
#test? ⇒ Boolean
Determines if the content will fetched from the server
149 150 151 |
# File 'lib/copycopter_client/configuration.rb', line 149 def test? test_environments.include? environment_name end |
#to_hash ⇒ Hash
Returns a hash of all configurable options
118 119 120 121 122 123 124 |
# File 'lib/copycopter_client/configuration.rb', line 118 def to_hash = { :public => public? } OPTIONS.inject() do |hash, option| hash.merge option.to_sym => send(option) end end |