Class: Localeapp::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/localeapp/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/localeapp/configuration.rb', line 101

def initialize
  @host                            = 'api.localeapp.com'
  @secure                          = true
  @ssl_verify                      = false
  @disabled_sending_environments   = %w(test cucumber production)
  @disabled_reloading_environments = %w(test cucumber production)
  @disabled_polling_environments   = %w(test cucumber production)
  @sending_environments            = %w(development)
  @reloading_environments          = %w(development)
  @polling_environments            = %w(development)
  @poll_interval                   = 0
  @synchronization_data_file       = File.join('log', 'localeapp.yml')
  @daemon_pid_file                 = File.join('tmp', 'pids', 'localeapp.pid')
  @daemon_log_file                 = File.join('log', 'localeapp_daemon.log')
  @translation_data_directory      = File.join('config', 'locales')
  if ENV['DEBUG']
    require 'logger'
    @logger = Logger.new(STDOUT)
  end
end

Instance Attribute Details

#api_keyObject

The API key for your project, found on the project edit form



5
6
7
# File 'lib/localeapp/configuration.rb', line 5

def api_key
  @api_key
end

#daemon_log_fileObject

The complete path to the log file where we store information about daemon actions default: RAILS_ROOT/log/localeapp_daemon.log



92
93
94
# File 'lib/localeapp/configuration.rb', line 92

def daemon_log_file
  @daemon_log_file
end

#daemon_pid_fileObject

The complete path to the pid file where we store information about daemon default: RAILS_ROOT/tmp/pids/localeapp.pid



88
89
90
# File 'lib/localeapp/configuration.rb', line 88

def daemon_pid_file
  @daemon_pid_file
end

#disabled_polling_environmentsObject

Deprecated.

Use #polling_environments instead. This is safer but make sure to reverse your logic if you’ve changed the defaults

The names of environments where updates aren’t pulled (defaults to ‘test’, ‘cucumber’, ‘production’)



68
69
70
# File 'lib/localeapp/configuration.rb', line 68

def disabled_polling_environments
  @disabled_polling_environments
end

#disabled_reloading_environmentsObject

Deprecated.

Use #reloading_environments instead. This is safer but make sure to reverse your logic if you’ve changed the defaults

The names of environments where I18n.reload isn’t called for each request (defaults to ‘test’, ‘cucumber’, ‘production’)



59
60
61
# File 'lib/localeapp/configuration.rb', line 59

def disabled_reloading_environments
  @disabled_reloading_environments
end

#disabled_sending_environmentsObject

Deprecated.

Use #sending_environments instead. This is safer but make sure to reverse your logic if you’ve changed the defaults

The names of environments where notifications aren’t sent (defaults to ‘test’, ‘cucumber’, ‘production’)



50
51
52
# File 'lib/localeapp/configuration.rb', line 50

def disabled_sending_environments
  @disabled_sending_environments
end

#environment_nameObject

The name of the environment the application is running in



29
30
31
# File 'lib/localeapp/configuration.rb', line 29

def environment_name
  @environment_name
end

#hostObject

The host to connect to (defaults to api.localeapp.com)



8
9
10
# File 'lib/localeapp/configuration.rb', line 8

def host
  @host
end

#http_auth_passwordObject

Returns the value of attribute http_auth_password.



26
27
28
# File 'lib/localeapp/configuration.rb', line 26

def http_auth_password
  @http_auth_password
end

#http_auth_usernameObject

Returns the value of attribute http_auth_username.



25
26
27
# File 'lib/localeapp/configuration.rb', line 25

def http_auth_username
  @http_auth_username
end

#loggerObject

The logger used by Localeapp



75
76
77
# File 'lib/localeapp/configuration.rb', line 75

def logger
  @logger
end

#poll_intervalObject

The number of seconds to wait before asking the service for new translations (defaults to 0 - every request).



79
80
81
# File 'lib/localeapp/configuration.rb', line 79

def poll_interval
  @poll_interval
end

#polling_environmentsObject

The names of environments where updates aren’t pulled (defaults to ‘development’)



45
46
47
# File 'lib/localeapp/configuration.rb', line 45

def polling_environments
  @polling_environments
end

#portObject

The port to connect to if it’s not the default one



23
24
25
# File 'lib/localeapp/configuration.rb', line 23

def port
  @port
end

#project_rootObject

The path to the project in which the translation occurred, such as the RAILS_ROOT



33
34
35
# File 'lib/localeapp/configuration.rb', line 33

def project_root
  @project_root
end

#proxyObject

The proxy to connect via



11
12
13
# File 'lib/localeapp/configuration.rb', line 11

def proxy
  @proxy
end

#reloading_environmentsObject

The names of environments where I18n.reload is called for each request (defaults to ‘development’)



41
42
43
# File 'lib/localeapp/configuration.rb', line 41

def reloading_environments
  @reloading_environments
end

#secureObject

Whether to use https or not (defaults to true)



14
15
16
# File 'lib/localeapp/configuration.rb', line 14

def secure
  @secure
end

#sending_environmentsObject

The names of environments where notifications are sent (defaults to ‘development’)



37
38
39
# File 'lib/localeapp/configuration.rb', line 37

def sending_environments
  @sending_environments
end

#ssl_ca_fileObject

Path to local CA certs bundle



20
21
22
# File 'lib/localeapp/configuration.rb', line 20

def ssl_ca_file
  @ssl_ca_file
end

#ssl_verifyObject

Whether to verify ssl server certificates or not (defaults to false, see README)



17
18
19
# File 'lib/localeapp/configuration.rb', line 17

def ssl_verify
  @ssl_verify
end

#synchronization_data_fileObject

The complete path to the data file where we store synchronization information (defaults to ./localeapp.yml) local_app/rails overwrites this to RAILS_ROOT/log/localeapp.yml



84
85
86
# File 'lib/localeapp/configuration.rb', line 84

def synchronization_data_file
  @synchronization_data_file
end

#translation_data_directoryObject

The complete path to the directory where translations are stored



95
96
97
# File 'lib/localeapp/configuration.rb', line 95

def translation_data_directory
  @translation_data_directory
end

Instance Method Details

#deprecated_environment_config_used?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/localeapp/configuration.rb', line 97

def deprecated_environment_config_used?
  @deprecated_environment_config_used
end

#polling_disabled?Boolean

Returns:

  • (Boolean)


122
123
124
125
126
127
128
129
# File 'lib/localeapp/configuration.rb', line 122

def polling_disabled?
  if deprecated_environment_config_used?
    ::Localeapp.log "DEPRECATION: disabled_polling_environments is deprecated and will be removed. Use polling_environments instead and reverse the logic if you've changed the defaults"
    disabled_polling_environments.map { |v| v.to_s }.include?(environment_name)
  else
    !polling_environments.map { |v| v.to_s }.include?(environment_name)
  end
end

#reloading_disabled?Boolean

Returns:

  • (Boolean)


131
132
133
134
135
136
137
138
# File 'lib/localeapp/configuration.rb', line 131

def reloading_disabled?
  if deprecated_environment_config_used?
    ::Localeapp.log "DEPRECATION: disabled_reloading_environments is deprecated and will be removed. Use reloading_environments instead and reverse the logic if you've changed the defaults"
    disabled_reloading_environments.map { |v| v.to_s }.include?(environment_name)
  else
    !reloading_environments.map { |v| v.to_s }.include?(environment_name)
  end
end

#sending_disabled?Boolean

Returns:

  • (Boolean)


140
141
142
143
144
145
146
147
# File 'lib/localeapp/configuration.rb', line 140

def sending_disabled?
  if deprecated_environment_config_used?
    ::Localeapp.log "DEPRECATION: disabled_sending_environments is deprecated and will be removed. Use sending_environments instead and reverse the logic if you've changed the defaults"
    disabled_sending_environments.map { |v| v.to_s }.include?(environment_name)
  else
    !sending_environments.map { |v| v.to_s }.include?(environment_name)
  end
end

#write_initial(path) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/localeapp/configuration.rb', line 149

def write_initial(path)
  dir = File.dirname(path)
  FileUtils.mkdir_p(dir)
  File.open(path, 'w+') do |file|
    file.write "require 'localeapp/rails'\n\nLocaleapp.configure do |config|\n  config.api_key = '\#{@api_key}'\nend\n"
  end
end