lib/singlettings/rails.rb in singlettings-0.0.7 vs lib/singlettings/rails.rb in singlettings-0.0.8
- old
+ new
@@ -1,12 +1,61 @@
require "singlettings/base"
module Singlettings
+
+ class RailsHooker
+ def self.hook_rails!
+ if defined?(::Rails)
+ config_path = "#{::Rails.root.to_s}/config/"
+ self.load_yaml_files! config_path
+ end
+ end
+
+ def self.load_yaml_files!(load_path)
+ # Load singletting.yml
+ files = []
+
+ singletting = "#{load_path}singletting.yml"
+ files << singletting if File.exists?(singletting)
+
+ # Add MyColorWay Flavoured yetting.yml
+ yetting = "#{load_path}yetting.yml"
+ files << yetting if File.exists? yetting
+
+ # Add namespaced files
+ files += Dir.glob("#{load_path}singlettings/**/*.yml")
+
+ files.each do |file|
+ self.eval_yaml file
+ end
+ end
+
+ # This method needs ActiveSupport
+ def self.eval_yaml(file)
+ base_name = File.basename(file).gsub(".yml", "").camelize
+ if base_name == "Singletting" or base_name == "Yetting"
+ klass_name = base_name
+ else
+ klass_name = "Singletting#{base_name}"
+ end
+ Object.const_set(klass_name, self.eval_yaml_class(file))
+ end
+
+ # Return specified anonymous class
+ def self.eval_yaml_class(file)
+ klass = Class.new(Singlettings::Base) do
+ source file
+ ns ::Rails.env
+ end
+ return klass
+ end
+ end
+
def self.hook_rails!
if defined?(::Rails)
config_path = "#{::Rails.root.to_s}/config/"
- self.load_yaml_files! config_path
+ RailsHooker.load_yaml_files! config_path
end
end
class Rails < ::Rails::Engine
# The priorities of ActiveSupport hooks are shown as below:
@@ -22,44 +71,6 @@
config.before_configuration do
Singlettings.hook_rails!
end
end if defined?(::Rails)
- def self.load_yaml_files!(load_path)
- # Load singletting.yml
- files = []
-
- singletting = "#{load_path}singletting.yml"
- files << singletting if File.exists?(singletting)
-
- # Add MyColorWay Flavoured yetting.yml
- yetting = "#{load_path}yetting.yml"
- files << yetting if File.exists? yetting
-
- # Add namespaced files
- files += Dir.glob("#{load_path}singlettings/**/*.yml")
-
- files.each do |file|
- self.eval_yaml file
- end
- end
-
- # This method needs ActiveSupport
- def self.eval_yaml(file)
- base_name = File.basename(file).gsub(".yml", "").camelize
- if base_name == "Singletting" or base_name == "Yetting"
- klass_name = base_name
- else
- klass_name = "Singletting#{base_name}"
- end
- Object.const_set(klass_name, self.eval_yaml_class(file))
- end
-
- # Return specified anonymous class
- def self.eval_yaml_class(file)
- klass = Class.new(Singlettings::Base) do
- source file
- ns ::Rails.env
- end
- return klass
- end
end
\ No newline at end of file