Module: Singlettings
- Defined in:
- lib/singlettings.rb,
lib/singlettings/base.rb,
lib/singlettings/rails.rb,
lib/singlettings/version.rb,
lib/singlettings/exceptions.rb
Defined Under Namespace
Classes: Base, FileNotSpecifiedError, NoSuchKeyError, NoSuchNamespaceError, Rails
Constant Summary collapse
- VERSION =
"0.0.6"
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
47 48 49 50 51 52 53 54 55 |
# File 'lib/singlettings/rails.rb', line 47 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, Singlettings.eval_yaml_class(file)) end |
.eval_yaml_class(file) ⇒ Object
Return specified anonymous class
58 59 60 61 62 63 64 |
# File 'lib/singlettings/rails.rb', line 58 def self.eval_yaml_class(file) klass = Class.new(Singlettings::Base) do source file ns ::Rails.env end return klass end |
.hook_rails! ⇒ Object
4 5 6 7 8 9 |
# File 'lib/singlettings/rails.rb', line 4 def self.hook_rails! if defined?(::Rails) config_path = "#{::Rails.root.to_s}/config/" Singlettings.load_yaml_files! config_path end end |
.load_yaml_files!(load_path) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/singlettings/rails.rb', line 27 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| Singlettings.eval_yaml file end end |