Class: Singlettings::RailsHooker
- Inherits:
-
Object
- Object
- Singlettings::RailsHooker
- Defined in:
- lib/singlettings/rails.rb
Class Method Summary collapse
-
.eval_yaml(file) ⇒ Object
This method needs ActiveSupport.
-
.eval_yaml_class(file) ⇒ Object
Return specified anonymous class.
- .hook_rails! ⇒ Object
- .load_yaml_files!(load_path) ⇒ Object
Class Method Details
.eval_yaml(file) ⇒ Object
This method needs ActiveSupport
33 34 35 36 37 38 39 40 41 |
# File 'lib/singlettings/rails.rb', line 33 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 |
.eval_yaml_class(file) ⇒ Object
Return specified anonymous class
44 45 46 47 48 49 50 |
# File 'lib/singlettings/rails.rb', line 44 def self.eval_yaml_class(file) klass = Class.new(Singlettings::Base) do source file ns ::Rails.env end return klass end |
.hook_rails! ⇒ Object
6 7 8 9 10 11 |
# File 'lib/singlettings/rails.rb', line 6 def self.hook_rails! if defined?(::Rails) config_path = "#{::Rails.root.to_s}/config/" self.load_yaml_files! config_path end end |
.load_yaml_files!(load_path) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/singlettings/rails.rb', line 13 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 |