Module: Rfm::Config
- Extended by:
- Config
- Included in:
- Base, Config, Database, Factory, Layout, Layout::SubLayout, Resultset, Server, XmlParser
- Defined in:
- lib/rfm/utilities/config.rb
Overview
Top level config hash accepts any defined config parameters, or group-name keys pointing to config subsets. The subsets can be any grouping of defined config parameters, as a hash. See CONFIG_KEYS for defined config parameters.
Instance Method Summary collapse
-
#config(*args, &block) ⇒ Object
Set @config with args & options hash.
-
#config_clear(*args) ⇒ Object
Sets @config just as above config method, but clears @config first.
-
#get_config(*arguments) ⇒ Object
Gets top level settings, merged with local and ad-hoc settings.
-
#sanitize_config(conf = {}, keep = [], dupe = false) ⇒ Object
Keep should be a list of strings representing keys to keep.
Instance Method Details
#config(*args, &block) ⇒ Object
Set @config with args & options hash. Args should be symbols representing configuration groups, with optional config hash as last arg, to be merged on top. Returns @config.
Sets @config with :use => :group1, :layout => ‘my_layout’
config :group1, :layout => 'my_layout
Factory.server, Factory.database, Factory.layout, and Base.config can take a string as the first argument, refering to the relevent server/database/layout name.
Pass a string as the first argument, to be used in the immediate context
config 'my_layout' # in the model, to set model configuration
Factory.layout 'my_layout', :my_group # to get a layout from settings in :my_group
59 60 61 62 63 64 |
# File 'lib/rfm/utilities/config.rb', line 59 def config(*args, &block) opt = args. @config ||= {} config_write(opt, args, &block) @config end |
#config_clear(*args) ⇒ Object
Sets @config just as above config method, but clears @config first.
67 68 69 70 71 72 |
# File 'lib/rfm/utilities/config.rb', line 67 def config_clear(*args) opt = args. @config = {} config_write(opt, args) @config end |
#get_config(*arguments) ⇒ Object
Gets top level settings, merged with local and ad-hoc settings.
get_config :layout => 'my_layout
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rfm/utilities/config.rb', line 86 def get_config(*arguments) args = arguments.clone @config ||= {} opt = args. strings = opt[:strings].rfm_force_array || [] symbols = opt[:use].rfm_force_array || [] objects = opt[:objects].rfm_force_array || [] args.each do |arg| case true when arg.is_a?(String) ; strings << arg when arg.is_a?(Symbol) ; symbols << arg else objects.unshift arg end end rslt = config_merge_with_parent(symbols).merge(opt) #using = rslt[:using].rfm_force_array sanitize_config(rslt, CONFIG_DONT_STORE, false) rslt[:using].delete "" rslt[:parents].delete "" rslt.merge(:strings=>strings, :objects=>objects) end |
#sanitize_config(conf = {}, keep = [], dupe = false) ⇒ Object
Keep should be a list of strings representing keys to keep.
110 111 112 113 114 |
# File 'lib/rfm/utilities/config.rb', line 110 def sanitize_config(conf={}, keep=[], dupe=false) (conf = conf.clone) if dupe conf.reject!{|k,v| (!CONFIG_KEYS.include?(k.to_s) or [{},[],''].include?(v)) and !keep.include? k.to_s } conf end |