Module: Rfm::Config

Extended by:
Config
Included in:
Base, Config, Connection, Database, Factory, Layout, Resultset, Server
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.

Constant Summary collapse

CONFIG_KEYS =
%w(
file_name
file_path
parser
host
port
proxy
account_name
password
database
layout
ignore_bad_data
ssl
root_cert
root_cert_name
root_cert_path
warn_on_redirect
raise_on_401
timeout
log_actions
log_responses
log_parser
use
parent
grammar
field_mapping
capture_strings_with
logger
CONFIG_DONT_STORE =

capture_strings_with)

%w(strings using parents symbols objects)

Instance Method Summary collapse

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

62
63
64
65
66
67
# File 'lib/rfm/utilities/config.rb', line 62

def config(*args, &block)
	@config ||= {}
	return @config if args.empty?
config_write(*args, &block)
@config
end

#config_clear(*args) ⇒ Object

Sets @config just as above config method, but clears @config first.


70
71
72
73
74
75
# File 'lib/rfm/utilities/config.rb', line 70

def config_clear(*args)
	@config = {}
	return @config if args.empty?
config_write(*args)
@config
end

#get_config(*arguments) ⇒ Object

Gets top level settings, merged with local and ad-hoc settings.

get_config :layout => 'my_layout

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/rfm/utilities/config.rb', line 89

def get_config(*arguments)
	#puts caller_locations(1,1)[0]
	args = arguments.clone
	@config ||= {}
	options = config_extract_options!(*args)
	strings = options[:strings].rfm_force_array || []
	symbols = options[:symbols].rfm_force_array.concat(options[:hash][:use].rfm_force_array) || []
	objects = options[:objects].rfm_force_array || []

rslt = config_merge_with_parent(symbols).merge(options[:hash])#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

#logObject


113
114
115
# File 'lib/rfm/utilities/config.rb', line 113

def log
	Rfm.log
end

#state(*args) ⇒ Object


106
107
108
109
110
111
# File 'lib/rfm/utilities/config.rb', line 106

def state(*args)
	return @_state if args.empty? && !@state.nil? && (RUBY_VERSION[0,1].to_i > 1 ? (caller_locations(1,1) == @_last_state_caller) : false)
	@_state = get_config(*args)
	(@_last_state_caller = caller_locations(1,1)) if RUBY_VERSION[0,1].to_i > 1
	@_state
end