Class: ActiveConfig::Suffixes
- Inherits:
-
Object
- Object
- ActiveConfig::Suffixes
- Defined in:
- lib/active_config/suffixes.rb
Instance Attribute Summary collapse
-
#ac_instance ⇒ Object
Returns the value of attribute ac_instance.
-
#priority ⇒ Object
writeonly
Sets the attribute priority.
-
#symbols ⇒ Object
readonly
Returns the value of attribute symbols.
Instance Method Summary collapse
- #file(fname) ⇒ Object
- #for(file) ⇒ Object
-
#initialize(*args) ⇒ Suffixes
constructor
A new instance of Suffixes.
- #method_missing(method, val = nil) ⇒ Object
- #overlay=(new_overlay) ⇒ Object
- #suffixes(ary = @priority) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Suffixes
Returns a new instance of Suffixes.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/active_config/suffixes.rb', line 27 def initialize(*args) ac_instance=args.shift @symbols=HashWithHooks.new @symbols[:hostname]=proc {|sym_table| ENV['ACTIVE_CONFIG_HOSTNAME'] || Socket.gethostname } @symbols[:hostname_short]=proc {|sym_table| sym_table[:hostname].call(sym_table).sub(/\..*$/, '').freeze} @symbols[:rails_env]=proc { |sym_table| (RAILS_ENV if defined?(RAILS_ENV))||ENV['RAILS_ENV']} @symbols[:overlay]=proc { |sym_table| ENV['ACTIVE_CONFIG_OVERLAY']} @symbols.add_write_hook do ac_instance.flush_cache end @priority=[ nil, :rails_env, [:rails_env,:local], :overlay, [:overlay,:local], [:hostname_short], [:hostname_short, :local], :hostname, [:hostname, :local], :local, ] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, val = nil) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/active_config/suffixes.rb', line 52 def method_missing method, val=nil super if method.to_s=~/^_/ if method.to_s=~/^(.*)=$/ ac_instance._flush_cache return @symbols[$1]=val end ret=@symbols[method] if ret return ret.call(@symbols) if ret.respond_to?(:call) return ret end super end |
Instance Attribute Details
#ac_instance ⇒ Object
Returns the value of attribute ac_instance.
20 21 22 |
# File 'lib/active_config/suffixes.rb', line 20 def ac_instance @ac_instance end |
#priority=(value) ⇒ Object (writeonly)
Sets the attribute priority
19 20 21 |
# File 'lib/active_config/suffixes.rb', line 19 def priority=(value) @priority = value end |
#symbols ⇒ Object (readonly)
Returns the value of attribute symbols.
21 22 23 |
# File 'lib/active_config/suffixes.rb', line 21 def symbols @symbols end |
Instance Method Details
#file(fname) ⇒ Object
80 81 82 83 84 |
# File 'lib/active_config/suffixes.rb', line 80 def file fname suffixes.map{|m|m="#{m}" if m "#{fname}#{m}.yml" } end |
#for(file) ⇒ Object
65 66 67 |
# File 'lib/active_config/suffixes.rb', line 65 def for file suffixes.map { |this_suffix| [file,*this_suffix].compact.join('_')}.compact.uniq end |
#overlay=(new_overlay) ⇒ Object
23 24 25 26 |
# File 'lib/active_config/suffixes.rb', line 23 def ac_instance._flush_cache @symbols[:overlay]=(.respond_to?(:upcase) ? .upcase : ) end |
#suffixes(ary = @priority) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/active_config/suffixes.rb', line 68 def suffixes ary=@priority ary.map{|e| if Array===e t=self.suffixes(e).compact t.size > 0 ? t.join('_') : nil elsif @symbols[e] method_missing(e) else e && e.to_s end } end |