Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMarius Mathiesen <marius@gitorious.org>2012-11-13 13:06:24 (GMT)
committer Marius Mathiesen <marius@gitorious.org>2012-11-13 13:06:24 (GMT)
commit4e0d4a31ff12f9df3fd3b43e2feefe7779c85cea (patch)
tree751b4a07dd89979967c98a39693d53f26980397e /lib
parenta4a307e9e7ed68edadc17848f51159026bf19cf8 (diff)
Extract logic for custom initializer/yaml file pair
Introducing Gitorious.on_config, which simplifies this.
Diffstat (limited to 'lib')
-rw-r--r--lib/gitorious/on_config.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/gitorious/on_config.rb b/lib/gitorious/on_config.rb
new file mode 100644
index 0000000..c3bc7b0
--- /dev/null
+++ b/lib/gitorious/on_config.rb
@@ -0,0 +1,30 @@
+# encoding: utf-8
+#--
+# Copyright (C) 2012 Gitorious AS
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#++
+module Gitorious
+ # If the file Rails.root + config/config_file exists, load this as a
+ # YAML file, fetch the section under Rails.env and yield these settings
+ #
+ # See config/initializers/resque.rb / config/resque.yml for an
+ # example
+ def self.on_config(config_file)
+ path = Rails.root + "config/#{config_file}"
+ if path.exist?
+ yield YAML::load_file(path)[Rails.env]
+ end
+ end
+end