Method: Arrow::Cache#initialize

Defined in:
lib/arrow/cache.rb

#initialize(name, config = {}, &cleanup) ⇒ Cache

Create a new cache. This merges the DefaultConfig with the specified values and transforms camelCased keys into under_barred ones.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/arrow/cache.rb', line 53

def initialize( name, config={}, &cleanup )
	@name = name

	# Merge defaults and specified values
	merged = DefaultConfig.merge( config )

	# Transform the config hash into the form the superclass expects
	merged.each_key do |key|
		lckey = key.to_s.gsub( /(.)([A-Z])/ ) {|match|
			match[0,1] + "_" + match[1,1].downcase
		}.to_sym

		next if key == lckey
		merged[ lckey ] = merged.delete( key )
	end

	# Register this instance with the class for introspection (costs
	# much less than ObjectSpace.each_object).
	obj = super( merged, &cleanup )
	self.class.extent << obj

	return obj
end