Sha256: 67a064535c44f81a5c88b27e998503175e356b1c77ec54832b183a9a846c869f

Contents?: true

Size: 824 Bytes

Versions: 29

Compression:

Stored size: 824 Bytes

Contents

module Shaddox
	class Settings < Hash
		def method_missing(meth, *args, &blk)
			name = meth.to_s

			return evaluate(self[meth])  if name.size == 1

			# Ruby 1.8.7 doesn't let you do string[-1]
			key, suffix = name[0..-2].to_sym, name[-1..-1]

			case suffix
			when '='
				self[key] = args.first
			when '?'
				include? key
			when '!'
				raise Error, "Setting :#{key} is not set" unless include?(key)
				evaluate self[key]
			else
				evaluate self[meth]
			end
		end

		def evaluate(value)
			if value.is_a?(Proc)
				value.call
			else
				value
			end
		end
	end
	module SettingContainer
		def init_settings(default_settings = {})
			@settings = Settings.new.update(default_settings)
		end

		# Hook to loop up values in @info
		def method_missing(meth, *args, &blk)
			@settings.send meth, *args
		end
	end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
shaddox-0.0.10 lib/shaddox/settings.rb
shaddox-0.0.9 lib/shaddox/settings.rb
shaddox-0.0.8 lib/shaddox/settings.rb
shaddox-0.0.7 lib/shaddox/settings.rb
shaddox-0.0.6 lib/shaddox/settings.rb
shaddox-0.0.5 lib/shaddox/settings.rb
shaddox-0.0.4 lib/shaddox/settings.rb
shaddox-0.0.3 lib/shaddox/settings.rb
shaddox-0.0.2 lib/shaddox/settings.rb