module FigMagic
Constants
- VERSION
Attributes
yml[RW]
parent[R]
Public Class Methods
included(cls)
click to toggle source
# File lib/fig_magic.rb, line 32 def self.included(cls) @parent = cls translators.each do |translator| Translation.send :include, translator end end
locale=(value)
click to toggle source
# File lib/fig_magic.rb, line 28 def self.locale=(value) Faker::Config.locale = value end
Private Class Methods
add_translator(translator)
click to toggle source
# File lib/fig_magic.rb, line 84 def add_translator(translator) translators << translator end
default_directory()
click to toggle source
# File lib/fig_magic.rb, line 80 def default_directory 'config/' end
translators()
click to toggle source
# File lib/fig_magic.rb, line 88 def translators @translators ||= [] end
Public Instance Methods
data_for(key, additional={})
click to toggle source
# File lib/fig_magic.rb, line 39 def data_for(key, additional={}) if key.is_a?(String) && key.match(%r{/}) filename, record = key.split('/') FigMagic.load("#{filename}.yml") else record = key.to_s FigMagic.load(the_file) unless FigMagic.yml end data = FigMagic.yml[record] raise ArgumentError, "Undefined key #{key}" unless data prep_data data.merge(additional).clone end
Private Instance Methods
prep_data(data)
click to toggle source
# File lib/fig_magic.rb, line 58 def prep_data(data) data.each do |key, value| unless value.nil? next if !value.respond_to?('[]') || value.is_a?(Numeric) next if value.is_a?(Hash) data[key] = translate(value[1..-1]) if value[0,1] == "~" end end data end
the_file()
click to toggle source
# File lib/fig_magic.rb, line 54 def the_file ENV['DATA_MAGIC_FILE'] ? ENV['DATA_MAGIC_FILE'] : 'default.yml' end
translate(value)
click to toggle source
# File lib/fig_magic.rb, line 69 def translate(value) translation.send :process, value end
translation()
click to toggle source
# File lib/fig_magic.rb, line 73 def translation @translation ||= Translation.new parent end