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.30 lib/shaddox/settings.rb
shaddox-0.0.29 lib/shaddox/settings.rb
shaddox-0.0.28 lib/shaddox/settings.rb
shaddox-0.0.27 lib/shaddox/settings.rb
shaddox-0.0.26 lib/shaddox/settings.rb
shaddox-0.0.25 lib/shaddox/settings.rb
shaddox-0.0.24 lib/shaddox/settings.rb
shaddox-0.0.23 lib/shaddox/settings.rb
shaddox-0.0.22 lib/shaddox/settings.rb
shaddox-0.0.21 lib/shaddox/settings.rb
shaddox-0.0.20 lib/shaddox/settings.rb
shaddox-0.0.19 lib/shaddox/settings.rb
shaddox-0.0.18 lib/shaddox/settings.rb
shaddox-0.0.17 lib/shaddox/settings.rb
shaddox-0.0.16 lib/shaddox/settings.rb
shaddox-0.0.15 lib/shaddox/settings.rb
shaddox-0.0.14 lib/shaddox/settings.rb
shaddox-0.0.13 lib/shaddox/settings.rb
shaddox-0.0.12 lib/shaddox/settings.rb
shaddox-0.0.11 lib/shaddox/settings.rb