From: Tom Hughes Date: Wed, 4 Aug 2010 21:06:05 +0000 (+0100) Subject: Rework application configuration X-Git-Tag: live~6257^2~35 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/f07819d81a7437e58c6e64c2e76ba7e54fad9034 Rework application configuration Use a preinitializer to load the settings from application.yml so that they are available as early as possible. All settings can also be overridden using environment variables. The ad-hoc settins in environment.rb are then moved to this new system so we have one consistent location for settings. --- diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index 7c6a140bd..447ebbc5f 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -172,7 +172,7 @@ class AmfController < ApplicationController def amf_handle_error_with_timeout(call,rootobj,rootid) amf_handle_error(call,rootobj,rootid) do - Timeout::timeout(APP_CONFIG['api_timeout'], OSM::APITimeoutError) do + Timeout::timeout(API_TIMEOUT, OSM::APITimeoutError) do yield end end diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index fc59ffcc7..d66fbb28f 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -18,7 +18,7 @@ class ApiController < ApplicationController return end - offset = page * APP_CONFIG['tracepoints_per_page'] + offset = page * TRACEPOINTS_PER_PAGE # Figure out the bbox bbox = params['bbox'] @@ -39,7 +39,7 @@ class ApiController < ApplicationController end # get all the points - points = Tracepoint.find_by_area(min_lat, min_lon, max_lat, max_lon, :offset => offset, :limit => APP_CONFIG['tracepoints_per_page'], :order => "gpx_id DESC, trackid ASC, timestamp ASC" ) + points = Tracepoint.find_by_area(min_lat, min_lon, max_lat, max_lon, :offset => offset, :limit => TRACEPOINTS_PER_PAGE, :order => "gpx_id DESC, trackid ASC, timestamp ASC" ) doc = XML::Document.new doc.encoding = XML::Encoding::UTF_8 @@ -145,14 +145,14 @@ class ApiController < ApplicationController end # FIXME um why is this area using a different order for the lat/lon from above??? - @nodes = Node.find_by_area(min_lat, min_lon, max_lat, max_lon, :conditions => {:visible => true}, :include => :node_tags, :limit => APP_CONFIG['max_number_of_nodes']+1) + @nodes = Node.find_by_area(min_lat, min_lon, max_lat, max_lon, :conditions => {:visible => true}, :include => :node_tags, :limit => MAX_NUMBER_OF_NODES+1) # get all the nodes, by tag not yet working, waiting for change from NickB # need to be @nodes (instance var) so tests in /spec can be performed #@nodes = Node.search(bbox, params[:tag]) node_ids = @nodes.collect(&:id) - if node_ids.length > APP_CONFIG['max_number_of_nodes'] - report_error("You requested too many nodes (limit is #{APP_CONFIG['max_number_of_nodes']}). Either request a smaller area, or use planet.osm") + if node_ids.length > MAX_NUMBER_OF_NODES + report_error("You requested too many nodes (limit is #{MAX_NUMBER_OF_NODES}). Either request a smaller area, or use planet.osm") return end if node_ids.length == 0 @@ -295,19 +295,19 @@ class ApiController < ApplicationController version['maximum'] = "#{API_VERSION}"; api << version area = XML::Node.new 'area' - area['maximum'] = APP_CONFIG['max_request_area'].to_s; + area['maximum'] = MAX_REQUEST_AREA.to_s; api << area tracepoints = XML::Node.new 'tracepoints' - tracepoints['per_page'] = APP_CONFIG['tracepoints_per_page'].to_s + tracepoints['per_page'] = TRACEPOINTS_PER_PAGE.to_s api << tracepoints waynodes = XML::Node.new 'waynodes' - waynodes['maximum'] = APP_CONFIG['max_number_of_way_nodes'].to_s + waynodes['maximum'] = MAX_NUMBER_OF_WAY_NODES.to_s api << waynodes changesets = XML::Node.new 'changesets' changesets['maximum_elements'] = Changeset::MAX_ELEMENTS.to_s api << changesets timeout = XML::Node.new 'timeout' - timeout['seconds'] = APP_CONFIG['api_timeout'].to_s + timeout['seconds'] = API_TIMEOUT.to_s api << timeout doc.root << api diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1605e1133..6c32b74b2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,7 +2,7 @@ # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base - if OSM_STATUS == :database_readonly or OSM_STATUS == :database_offline + if STATUS == :database_readonly or STATUS == :database_offline session :off end @@ -120,20 +120,20 @@ class ApplicationController < ActionController::Base end def check_database_readable(need_api = false) - if OSM_STATUS == :database_offline or (need_api and OSM_STATUS == :api_offline) + if STATUS == :database_offline or (need_api and STATUS == :api_offline) redirect_to :controller => 'site', :action => 'offline' end end def check_database_writable(need_api = false) - if OSM_STATUS == :database_offline or OSM_STATUS == :database_readonly or - (need_api and (OSM_STATUS == :api_offline or OSM_STATUS == :api_readonly)) + if STATUS == :database_offline or STATUS == :database_readonly or + (need_api and (STATUS == :api_offline or STATUS == :api_readonly)) redirect_to :controller => 'site', :action => 'offline' end end def check_api_readable - if OSM_STATUS == :database_offline or OSM_STATUS == :api_offline + if STATUS == :database_offline or STATUS == :api_offline response.headers['Error'] = "Database offline for maintenance" render :nothing => true, :status => :service_unavailable return false @@ -141,8 +141,8 @@ class ApplicationController < ActionController::Base end def check_api_writable - if OSM_STATUS == :database_offline or OSM_STATUS == :database_readonly or - OSM_STATUS == :api_offline or OSM_STATUS == :api_readonly + if STATUS == :database_offline or STATUS == :database_readonly or + STATUS == :api_offline or STATUS == :api_readonly response.headers['Error'] = "Database offline for maintenance" render :nothing => true, :status => :service_unavailable return false @@ -219,7 +219,7 @@ class ApplicationController < ActionController::Base ## # wrap an api call in a timeout def api_call_timeout - SystemTimer.timeout_after(APP_CONFIG['api_timeout']) do + SystemTimer.timeout_after(API_TIMEOUT) do yield end rescue Timeout::Error @@ -229,7 +229,7 @@ class ApplicationController < ActionController::Base ## # wrap a web page in a timeout def web_timeout - SystemTimer.timeout_after(APP_CONFIG['web_timeout']) do + SystemTimer.timeout_after(WEB_TIMEOUT) do yield end rescue ActionView::TemplateError => ex diff --git a/app/controllers/diary_entry_controller.rb b/app/controllers/diary_entry_controller.rb index 320f3d029..73e9629e0 100644 --- a/app/controllers/diary_entry_controller.rb +++ b/app/controllers/diary_entry_controller.rb @@ -10,7 +10,7 @@ class DiaryEntryController < ApplicationController caches_action :list, :view, :layout => false caches_action :rss, :layout => true - cache_sweeper :diary_sweeper, :only => [:new, :edit, :comment, :hide, :hidecomment], :unless => OSM_STATUS == :database_offline + cache_sweeper :diary_sweeper, :only => [:new, :edit, :comment, :hide, :hidecomment], :unless => STATUS == :database_offline def new @title = t 'diary_entry.new.title' diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 2af95e5fa..d07b74f11 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -57,7 +57,7 @@ class GeocoderController < ApplicationController render :action => "error" else @results.push({:lat => lat, :lon => lon, - :zoom => APP_CONFIG['postcode_zoom'], + :zoom => POSTCODE_ZOOM, :name => "#{lat}, #{lon}"}) render :action => "results" @@ -78,7 +78,7 @@ class GeocoderController < ApplicationController unless response.match(/couldn't find this zip/) data = response.split(/\s*,\s+/) # lat,long,town,state,zip @results.push({:lat => data[0], :lon => data[1], - :zoom => APP_CONFIG['postcode_zoom'], + :zoom => POSTCODE_ZOOM, :prefix => "#{data[2]}, #{data[3]},", :name => data[4]}) end @@ -104,7 +104,7 @@ class GeocoderController < ApplicationController dataline = response.split(/\n/)[1] data = dataline.split(/,/) # easting,northing,postcode,lat,long postcode = data[2].gsub(/'/, "") - zoom = APP_CONFIG['postcode_zoom'] - postcode.count("#") + zoom = POSTCODE_ZOOM - postcode.count("#") @results.push({:lat => data[3], :lon => data[4], :zoom => zoom, :name => postcode}) end @@ -127,7 +127,7 @@ class GeocoderController < ApplicationController if response.get_elements("geodata/error").empty? @results.push({:lat => response.get_text("geodata/latt").to_s, :lon => response.get_text("geodata/longt").to_s, - :zoom => APP_CONFIG['postcode_zoom'], + :zoom => POSTCODE_ZOOM, :name => query.upcase}) end @@ -286,7 +286,7 @@ class GeocoderController < ApplicationController name = geoname.get_text("name").to_s country = geoname.get_text("countryName").to_s @results.push({:lat => lat, :lon => lon, - :zoom => APP_CONFIG['geonames_zoom'], + :zoom => GEONAMES_ZOOM, :name => name, :suffix => ", #{country}"}) end diff --git a/app/controllers/message_controller.rb b/app/controllers/message_controller.rb index 5db9cccfa..82e3f30f2 100644 --- a/app/controllers/message_controller.rb +++ b/app/controllers/message_controller.rb @@ -15,7 +15,7 @@ class MessageController < ApplicationController @to_user = User.find_by_display_name(params[:display_name]) if @to_user if params[:message] - if @user.sent_messages.count(:conditions => ["sent_on >= ?", Time.now.getutc - 1.hour]) >= APP_CONFIG['max_messages_per_hour'] + if @user.sent_messages.count(:conditions => ["sent_on >= ?", Time.now.getutc - 1.hour]) >= MAX_MESSAGES_PER_HOUR flash[:error] = t 'message.new.limit_exceeded' else @message = Message.new(params[:message]) diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index abd59aeb2..6751cf318 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -17,8 +17,8 @@ class TraceController < ApplicationController caches_action :list, :view, :layout => false caches_action :georss, :layout => true - cache_sweeper :trace_sweeper, :only => [:create, :edit, :delete, :api_create], :unless => OSM_STATUS == :database_offline - cache_sweeper :tracetag_sweeper, :only => [:create, :edit, :delete, :api_create], :unless => OSM_STATUS == :database_offline + cache_sweeper :trace_sweeper, :only => [:create, :edit, :delete, :api_create], :unless => STATUS == :database_offline + cache_sweeper :tracetag_sweeper, :only => [:create, :edit, :delete, :api_create], :unless => STATUS == :database_offline # Counts and selects pages of GPX traces for various criteria (by user, tags, public etc.). # target_user - if set, specifies the user to fetch traces for. if not set will fetch all traces @@ -395,11 +395,11 @@ private end def offline_warning - flash.now[:warning] = t 'trace.offline_warning.message' if OSM_STATUS == :gpx_offline + flash.now[:warning] = t 'trace.offline_warning.message' if STATUS == :gpx_offline end def offline_redirect - redirect_to :action => :offline if OSM_STATUS == :gpx_offline + redirect_to :action => :offline if STATUS == :gpx_offline end def default_visibility diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 0957853ce..e22a4992a 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -16,13 +16,13 @@ class UserController < ApplicationController filter_parameter_logging :password, :pass_crypt, :pass_crypt_confirmation - cache_sweeper :user_sweeper, :only => [:account, :set_status, :delete], :unless => OSM_STATUS == :database_offline + cache_sweeper :user_sweeper, :only => [:account, :set_status, :delete], :unless => STATUS == :database_offline def terms @title = t 'user.new.title' @user = User.new(params[:user]) - @legale = params[:legale] || OSM.IPToCountry(request.remote_ip) || APP_CONFIG['default_legale'] + @legale = params[:legale] || OSM.IPToCountry(request.remote_ip) || DEFAULT_LEGALE @text = OSM.legal_text_for_country(@legale) if request.xhr? diff --git a/app/models/node.rb b/app/models/node.rb index df6442b83..7db4aed09 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -58,7 +58,7 @@ class Node < ActiveRecord::Base find_by_area(min_lat, min_lon, max_lat, max_lon, :conditions => {:visible => true}, - :limit => APP_CONFIG['max_number_of_nodes']+1) + :limit => MAX_NUMBER_OF_NODES+1) end # Read in xml as text and return it's Node object representation diff --git a/app/models/notifier.rb b/app/models/notifier.rb index 364463336..a1fde49b3 100644 --- a/app/models/notifier.rb +++ b/app/models/notifier.rb @@ -105,7 +105,7 @@ private end def from_header(name, type, id, digest) - if domain = APP_CONFIG['messages_domain'] + if domain = MESSAGES_DOMAIN from quote_address_if_necessary("#{name} <#{type}-#{id}-#{digest[0,6]}@#{domain}>", "utf-8") end end diff --git a/app/models/spam_observer.rb b/app/models/spam_observer.rb index 21561f671..8b5212111 100644 --- a/app/models/spam_observer.rb +++ b/app/models/spam_observer.rb @@ -8,7 +8,7 @@ class SpamObserver < ActiveRecord::Observer when record.is_a?(DiaryComment): user = record.user end - if user.status == "active" and user.spam_score > APP_CONFIG['spam_threshold'] + if user.status == "active" and user.spam_score > SPAM_THRESHOLD user.update_attributes(:status => "suspended") end end diff --git a/app/models/user_block.rb b/app/models/user_block.rb index 23e1bcab6..8c7ae390b 100644 --- a/app/models/user_block.rb +++ b/app/models/user_block.rb @@ -5,7 +5,7 @@ class UserBlock < ActiveRecord::Base belongs_to :creator, :class_name => "User", :foreign_key => :creator_id belongs_to :revoker, :class_name => "User", :foreign_key => :revoker_id - PERIODS = APP_CONFIG['user_block_periods'] + PERIODS = USER_BLOCK_PERIODS ## # returns true if the block is currently active (i.e: the user can't diff --git a/app/models/way.rb b/app/models/way.rb index 639f4e69a..cc9343e7c 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -234,8 +234,8 @@ class Way < ActiveRecord::Base def preconditions_ok?(old_nodes = []) return false if self.nds.empty? - if self.nds.length > APP_CONFIG['max_number_of_way_nodes'] - raise OSM::APITooManyWayNodesError.new(self.id, self.nds.length, APP_CONFIG['max_number_of_way_nodes']) + if self.nds.length > MAX_NUMBER_OF_WAY_NODES + raise OSM::APITooManyWayNodesError.new(self.id, self.nds.length, MAX_NUMBER_OF_WAY_NODES) end # check only the new nodes, for efficiency - old nodes having been checked last time and can't diff --git a/app/views/browse/start.rjs b/app/views/browse/start.rjs index b045bc9ea..1b68043c9 100644 --- a/app/views/browse/start.rjs +++ b/app/views/browse/start.rjs @@ -185,8 +185,8 @@ page << < #{APP_CONFIG['max_request_area']}) { - setStatus(i18n("#{I18n.t('browse.start_rjs.unable_to_load_size', :max_bbox_size => APP_CONFIG['max_request_area'])}", { bbox_size: size })); + if (size > #{MAX_REQUEST_AREA}) { + setStatus(i18n("#{I18n.t('browse.start_rjs.unable_to_load_size', :max_bbox_size => MAX_REQUEST_AREA)}", { bbox_size: size })); } else { loadGML("/api/#{API_VERSION}/map?bbox=" + projected.toBBOX()); } diff --git a/app/views/export/start.rjs b/app/views/export/start.rjs index d556d8bf9..cc4d198cd 100644 --- a/app/views/export/start.rjs +++ b/app/views/export/start.rjs @@ -190,7 +190,7 @@ page << < #{APP_CONFIG['max_request_area']}) { + if (bounds.getWidth() * bounds.getHeight() > #{MAX_REQUEST_AREA}) { $("export_osm_too_large").style.display = "block"; } else { $("export_osm_too_large").style.display = "none"; @@ -198,7 +198,7 @@ page << < #{APP_CONFIG['max_request_area']}) { + if ($("format_osm").checked && bounds.getWidth() * bounds.getHeight() > #{MAX_REQUEST_AREA}) { $("export_commit").disabled = true; } else if ($("format_mapnik").checked && $("mapnik_scale").value < max_scale) { $("export_commit").disabled = true; diff --git a/app/views/layouts/site.html.erb b/app/views/layouts/site.html.erb index 6a820ef26..bc4b348a1 100644 --- a/app/views/layouts/site.html.erb +++ b/app/views/layouts/site.html.erb @@ -100,11 +100,11 @@ <% end %> - <% if OSM_STATUS == :database_offline or OSM_STATUS == :api_offline %> + <% if STATUS == :database_offline or STATUS == :api_offline %>
<%= t 'layouts.osm_offline' %>
- <% elsif OSM_STATUS == :database_readonly or OSM_STATUS == :api_readonly %> + <% elsif STATUS == :database_readonly or STATUS == :api_readonly %>
<%= t 'layouts.osm_read_only' %>
diff --git a/app/views/site/edit.html.erb b/app/views/site/edit.html.erb index 779abd352..e5bffd1e4 100644 --- a/app/views/site/edit.html.erb +++ b/app/views/site/edit.html.erb @@ -1,7 +1,7 @@ -<% if OSM_STATUS == :database_offline or OSM_STATUS == :api_offline %> +<% if STATUS == :database_offline or STATUS == :api_offline %>

<%= t 'layouts.osm_offline' %>

-<% elsif OSM_STATUS == :database_readonly or OSM_STATUS == :api_readonly %> +<% elsif STATUS == :database_readonly or STATUS == :api_readonly %>

<%= t 'layouts.osm_read_only' %>

<% elsif !@user.data_public? %> diff --git a/app/views/site/index.html.erb b/app/views/site/index.html.erb index 636e6929c..ddd66a861 100644 --- a/app/views/site/index.html.erb +++ b/app/views/site/index.html.erb @@ -125,7 +125,7 @@ end function mapInit(){ map = createMap("map"); - <% unless OSM_STATUS == :api_offline or OSM_STATUS == :database_offline %> + <% unless STATUS == :api_offline or STATUS == :database_offline %> map.dataLayer = new OpenLayers.Layer("<%= I18n.t 'browse.start_rjs.data_layer_name' %>", { "visibility": false }); map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData); map.addLayer(map.dataLayer); diff --git a/app/views/site/offline.html.erb b/app/views/site/offline.html.erb index b960ab66d..34a2eacc5 100644 --- a/app/views/site/offline.html.erb +++ b/app/views/site/offline.html.erb @@ -1,4 +1,4 @@ -<% if OSM_STATUS == :database_offline %> +<% if STATUS == :database_offline %>

<%= t 'layouts.osm_offline' %>

<% else %> diff --git a/app/views/trace/_trace.html.erb b/app/views/trace/_trace.html.erb index 509c346ed..8addd5c1c 100644 --- a/app/views/trace/_trace.html.erb +++ b/app/views/trace/_trace.html.erb @@ -1,7 +1,7 @@ <% cl = cycle('table0', 'table1') %> - <% if OSM_STATUS != :gpx_offline %> + <% if STATUS != :gpx_offline %> <% if trace.inserted %> <% else %> diff --git a/app/views/trace/view.html.erb b/app/views/trace/view.html.erb index bfef5d901..0d9b6213f 100644 --- a/app/views/trace/view.html.erb +++ b/app/views/trace/view.html.erb @@ -1,6 +1,6 @@

<%= t 'trace.view.heading', :name => h(@trace.name) %>

-<% if OSM_STATUS != :gpx_offline %> +<% if STATUS != :gpx_offline %> <% if @trace.inserted %> <% else %> diff --git a/config/application.yml b/config/application.yml index 95037f83e..b368d1fca 100644 --- a/config/application.yml +++ b/config/application.yml @@ -1,4 +1,21 @@ standard_settings: &standard_settings + # The server URL + server_url: "www.openstreetmap.org" + # The generator + generator: "OpenStreetMap server" + # Sender addresses for emails + email_from: "OpenStreetMap " + email_return_path: "bounces@openstreetmap.org" + # API version + api_version: "0.6" + # Application status - posstible values are: + # :online - online and operating normally + # :api_readonly - site online but API in read-only mode + # :api_offline - site online but API offline + # :database_readonly - database and site in read-only mode + # :database_offline - database offline with site in emergency mode + # :gpx_offline - gpx storage offline + status: :online # The maximum area you're allowed to request, in square degrees max_request_area: 0.25 # Number of GPS trace/trackpoints returned per-page diff --git a/config/environment.rb b/config/environment.rb index b1e0d437e..e2349573f 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,36 +1,8 @@ # Be sure to restart your server when you modify this file -# Uncomment below to force Rails into production mode when -# you don't control web/app server and can't set it the proper way -ENV['RAILS_ENV'] ||= 'production' - # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2.3.8' unless defined? RAILS_GEM_VERSION -# Set the server URL -SERVER_URL = ENV['OSM_SERVER_URL'] || 'www.openstreetmap.org' - -# Set the generator -GENERATOR = ENV['OSM_SERVER_GENERATOR'] || 'OpenStreetMap server' - -# Settings for generated emails (e.g. signup confirmation -EMAIL_FROM = ENV['OSM_EMAIL_FROM'] || 'OpenStreetMap ' -EMAIL_RETURN_PATH = ENV['OSM_EMAIL_RETURN_PATH'] || 'bounces@openstreetmap.org' - -# Application constants needed for routes.rb - must go before Initializer call -API_VERSION = ENV['OSM_API_VERSION'] || '0.6' - -# Set application status - possible settings are: -# -# :online - online and operating normally -# :api_readonly - site online but API in read-only mode -# :api_offline - site online but API offline -# :database_readonly - database and site in read-only mode -# :database_offline - database offline with site in emergency mode -# :gpx_offline - gpx storage offline -# -OSM_STATUS = :online - # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot') @@ -43,7 +15,7 @@ Rails::Initializer.run do |config| # config.load_paths += %W( #{RAILS_ROOT}/extras ) # Specify gems that this application depends on and have them installed with rake gems:install - unless OSM_STATUS == :database_offline + unless STATUS == :database_offline config.gem 'composite_primary_keys', :version => '2.2.2' end config.gem 'libxml-ruby', :version => '>= 1.1.1', :lib => 'libxml' @@ -59,7 +31,7 @@ Rails::Initializer.run do |config| # Skip frameworks you're not going to use. To use Rails without a database, # you must remove the Active Record framework. - if OSM_STATUS == :database_offline + if STATUS == :database_offline config.frameworks -= [ :active_record ] config.eager_load_paths = [] end diff --git a/config/initializers/load_configs.rb b/config/initializers/load_configs.rb deleted file mode 100644 index a189ac860..000000000 --- a/config/initializers/load_configs.rb +++ /dev/null @@ -1,4 +0,0 @@ -# This file loads various yml configuration files - -# Load application config -APP_CONFIG = YAML.load(File.read(RAILS_ROOT + "/config/application.yml"))[RAILS_ENV] diff --git a/config/initializers/memory_limits.rb b/config/initializers/memory_limits.rb index 6f553aff6..e2dcee23c 100644 --- a/config/initializers/memory_limits.rb +++ b/config/initializers/memory_limits.rb @@ -1,11 +1,11 @@ # Setup any specified hard limit on the virtual size of the process -if APP_CONFIG.include?('hard_memory_limit') and Process.const_defined?(:RLIMIT_AS) - Process.setrlimit Process::RLIMIT_AS, APP_CONFIG['hard_memory_limit']*1024*1024, Process::RLIM_INFINITY +if defined?(HARD_MEMORY_LIMIT) and Process.const_defined?(:RLIMIT_AS) + Process.setrlimit Process::RLIMIT_AS, HARD_MEMORY_LIMIT*1024*1024, Process::RLIM_INFINITY end # If we're running under passenger and a soft memory limit is # configured then setup some rack middleware to police the limit -if APP_CONFIG.include?('soft_memory_limit') and defined?(PhusionPassenger) +if defined?(SOFT_MEMORY_LIMIT) and defined?(PhusionPassenger) # Define some rack middleware to police the soft memory limit class MemoryLimit def initialize(app) @@ -17,7 +17,7 @@ if APP_CONFIG.include?('soft_memory_limit') and defined?(PhusionPassenger) status, headers, body = @app.call(env) # Restart if we've hit our memory limit - if resident_size > APP_CONFIG['soft_memory_limit'] + if resident_size > SOFT_MEMORY_LIMIT Process.kill("USR1", 0) end diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index 8ab000717..77fd39092 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -12,6 +12,6 @@ ActionController::Base.session = { # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information # (create the session table with "rake db:sessions:create") -unless OSM_STATUS == :database_offline or OSM_STATUS == :database_readonly +unless STATUS == :database_offline or STATUS == :database_readonly ActionController::Base.session_store = :sql_session_store end diff --git a/config/initializers/sql_session_store.rb b/config/initializers/sql_session_store.rb index 2b9543fc2..d2fc9801a 100644 --- a/config/initializers/sql_session_store.rb +++ b/config/initializers/sql_session_store.rb @@ -4,6 +4,6 @@ adapter = Rails.configuration.database_configuration[environment]["adapter"] session_class = adapter + "_session" # Configure SqlSessionStore -unless OSM_STATUS == :database_offline +unless STATUS == :database_offline SqlSessionStore.session_class = session_class.camelize.constantize end diff --git a/config/preinitializer.rb b/config/preinitializer.rb new file mode 100644 index 000000000..357e30218 --- /dev/null +++ b/config/preinitializer.rb @@ -0,0 +1,16 @@ +require 'yaml' + +config = YAML.load_file("#{RAILS_ROOT}/config/application.yml") +env = ENV['RAILS_ENV'] || 'development' + +ENV.each do |key,value| + if key.match(/^OSM_(.*)$/) + Object.const_set(Regexp.last_match(1).upcase, value) + end +end + +config[env].each do |key,value| + unless Object.const_defined?(key.upcase) + Object.const_set(key.upcase, value) + end +end diff --git a/lib/map_boundary.rb b/lib/map_boundary.rb index 6ac7e9f3d..f3accf2da 100644 --- a/lib/map_boundary.rb +++ b/lib/map_boundary.rb @@ -24,8 +24,8 @@ module MapBoundary # check the bbox isn't too large requested_area = (max_lat-min_lat)*(max_lon-min_lon) - if requested_area > APP_CONFIG['max_request_area'] - raise OSM::APIBadBoundingBox.new("The maximum bbox size is " + APP_CONFIG['max_request_area'].to_s + + if requested_area > MAX_REQUEST_AREA + raise OSM::APIBadBoundingBox.new("The maximum bbox size is " + MAX_REQUEST_AREA.to_s + ", and your request was too large. Either request a smaller area, or use planet.osm") end end diff --git a/lib/osm.rb b/lib/osm.rb index 704bc099c..eaee7c328 100644 --- a/lib/osm.rb +++ b/lib/osm.rb @@ -530,7 +530,7 @@ module OSM def self.legal_text_for_country(country_code) file_name = File.join(RAILS_ROOT, "config", "legales", country_code.to_s + ".yml") - file_name = File.join(RAILS_ROOT, "config", "legales", APP_CONFIG['default_legale'] + ".yml") unless File.exist? file_name + file_name = File.join(RAILS_ROOT, "config", "legales", DEFAULT_LEGALE + ".yml") unless File.exist? file_name YAML::load_file(file_name) end end diff --git a/lib/quova.rb b/lib/quova.rb index a7318d66e..ed5b9f491 100644 --- a/lib/quova.rb +++ b/lib/quova.rb @@ -17,8 +17,8 @@ module Quova ## # Access details for WSDL description WSDL_URL="https://webservices.quova.com/OnDemand/GeoPoint/v1/default.asmx?WSDL" - WSDL_USER = APP_CONFIG['quova_username'] - WSDL_PASS = APP_CONFIG['quova_password'] + WSDL_USER = QUOVA_USERNAME + WSDL_PASS = QUOVA_PASSWORD ## # Status codes diff --git a/test/functional/api_controller_test.rb b/test/functional/api_controller_test.rb index e1543726f..b4ac25cfe 100644 --- a/test/functional/api_controller_test.rb +++ b/test/functional/api_controller_test.rb @@ -147,7 +147,7 @@ class ApiControllerTest < ActionController::TestCase [ "trackpoints", "map" ].each do |tq| get tq, :bbox => bbox assert_response :bad_request, "The bbox:#{bbox} was expected to be too big" - assert_equal "The maximum bbox size is #{APP_CONFIG['max_request_area']}, and your request was too large. Either request a smaller area, or use planet.osm", @response.body, "bbox: #{bbox}" + assert_equal "The maximum bbox size is #{MAX_REQUEST_AREA}, and your request was too large. Either request a smaller area, or use planet.osm", @response.body, "bbox: #{bbox}" end end end @@ -264,8 +264,8 @@ class ApiControllerTest < ActionController::TestCase assert_select "osm:root[version='#{API_VERSION}'][generator='#{GENERATOR}']", :count => 1 do assert_select "api", :count => 1 do assert_select "version[minimum=#{API_VERSION}][maximum=#{API_VERSION}]", :count => 1 - assert_select "area[maximum=#{APP_CONFIG['max_request_area']}]", :count => 1 - assert_select "tracepoints[per_page=#{APP_CONFIG['tracepoints_per_page']}]", :count => 1 + assert_select "area[maximum=#{MAX_REQUEST_AREA}]", :count => 1 + assert_select "tracepoints[per_page=#{TRACEPOINTS_PER_PAGE}]", :count => 1 assert_select "changesets[maximum_elements=#{Changeset::MAX_ELEMENTS}]", :count => 1 end end diff --git a/test/unit/way_test.rb b/test/unit/way_test.rb index 39da76ec0..9c9ffe59a 100644 --- a/test/unit/way_test.rb +++ b/test/unit/way_test.rb @@ -26,7 +26,7 @@ class WayTest < ActiveSupport::TestCase way = Way.find(current_ways(:visible_way).id) assert way.valid? # it already has 1 node - 1.upto((APP_CONFIG['max_number_of_way_nodes']) / 2) { + 1.upto((MAX_NUMBER_OF_WAY_NODES) / 2) { way.add_nd_num(current_nodes(:used_node_1).id) way.add_nd_num(current_nodes(:used_node_2).id) }