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:
parent
a8c7256974
commit
d1d8da513c
2 changed files with 42 additions and 1 deletions
|
@ -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}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue