Add accessors to settings class

This commit is contained in:
Arthur Neves
2013-10-21 13:05:39 -04:00
parent c65d387705
commit 41f1855056
2 changed files with 35 additions and 3 deletions

View File

@@ -1,16 +1,18 @@
require 'active_support/hash_with_indifferent_access'
module ActiveModel
class Serializer
class Settings
def initialize
@data = {}
@data = ActiveSupport::HashWithIndifferentAccess.new
end
def [](key)
@data[key.to_s]
@data[key]
end
def []=(key, value)
@data[key.to_s] = value
@data[key] = value
end
def each(&block)
@@ -20,6 +22,17 @@ module ActiveModel
def clear
@data.clear
end
def method_missing(name, *args)
return @data[name] if @data.include?(name)
match = name.to_s.match(/(.*?)([?=]?)$/)
case match[2]
when "="
@data[match[1]] = args.first
when "?"
!!@data[match[1]]
end
end
end
SETTINGS = Settings.new