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
	template
	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


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

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.



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

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


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

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



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

def log
	Rfm.log
end

#state(*args) ⇒ Object



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

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