Added code to generate a property? method for properties casted as :boolean

Signed-off-by: Matt Aimonetti <mattaimonetti@gmail.com>
This commit is contained in:
John Wood 2009-07-25 11:12:03 +08:00 committed by Matt Aimonetti
parent a8c7256974
commit d1d8da513c
2 changed files with 42 additions and 1 deletions

View file

@ -77,6 +77,9 @@ module CouchRest
# Float instances don't get initialized with #new
elsif ((property.init_method == 'new') && target == 'Float')
cast_float(self[key])
# 'boolean' type is simply used to generate a property? accessor method
elsif ((property.init_method == 'new') && target == 'boolean')
self[key]
else
# Let people use :send as a Time parse arg
klass = ::CouchRest.constantize(target)
@ -128,6 +131,18 @@ module CouchRest
end
EOS
if property.type == 'boolean'
class_eval <<-EOS, __FILE__, __LINE__
def #{property.name}?
if self['#{property.name}'].nil? || self['#{property.name}'] == false || self['#{property.name}'].to_s.downcase == 'false'
false
else
true
end
end
EOS
end
if property.alias
class_eval <<-EOS, __FILE__, __LINE__
alias #{property.alias.to_sym} #{property.name.to_sym}