Class: ConfigXmlClass

Inherits:
ConfigClass show all
Defined in:
lib/buzzcore/config.rb

Overview

use like this :

in initializer or environment.rb : APP_CONFIG = ConfigXmlClass.from_file( SITE_CONFIG_DEFAULTS = { :something => String, # giving a class means the type is the given class, and the default value is nil :session_key => ‘_session’, :upload_path=> ‘cms/uploads’, :thumbs_cache => File.expand_path(‘public/thumbs_cache’,RAILS_ROOT), # make sure this exists with correct permissions :thumbs_url => ‘/thumbs_cache’ }, File.expand_path(‘config/config.xml’,RAILS_ROOT) )

config/logikal.config.xml :

<?xml version=“1.0” encoding=“UTF-8”?> <Config> <SimpleItems> <Item Name=“upload_path”>../shared/uploads</Item> <Item Name=“something”>a value</Item> </SimpleItems> </Config>

then throughout app eg. :

APP_CONFIG

Instance Attribute Summary collapse

Attributes inherited from ConfigClass

#default_values

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ConfigClass

#copy_booleans, #copy_floats, #copy_ints, #copy_item, #copy_strings, #read, #reset, #set_boolean, #set_float, #set_int, #set_symbol, #to_hash

Constructor Details

#initialize(aDefaultValues, aConfig) ⇒ ConfigXmlClass

Returns a new instance of ConfigXmlClass.



148
149
150
151
152
# File 'lib/buzzcore/config.rb', line 148

def initialize(aDefaultValues,aConfig)
	return super(aDefaultValues,aConfig) unless aConfig.is_a?(REXML::Element)
	@xmlRoot = aConfig.deep_clone
	super(aDefaultValues,XmlUtils.read_simple_items(@xmlRoot,'SimpleItems').symbolize_keys)
end

Instance Attribute Details

#xmlRootObject

Returns the value of attribute xmlRoot.



147
148
149
# File 'lib/buzzcore/config.rb', line 147

def xmlRoot
  @xmlRoot
end

Class Method Details

.from_file(aDefaultValues, aFile) ⇒ Object



154
155
156
157
# File 'lib/buzzcore/config.rb', line 154

def self.from_file(aDefaultValues,aFile)
	xml = XmlUtils.get_file_root(aFile)
	return ConfigXmlClass.new(aDefaultValues,xml)
end