Removing old fashioned class_evals (more to go)
This commit is contained in:
parent
31b52ba012
commit
a8a1372e57
|
@ -149,7 +149,6 @@ module CouchRest
|
|||
# These properties are casted as Time objects, so they should always
|
||||
# be set to UTC.
|
||||
def timestamps!
|
||||
class_eval <<-EOS, __FILE__, __LINE__
|
||||
property(:updated_at, Time, :read_only => true, :protected => true, :auto_validation => false)
|
||||
property(:created_at, Time, :read_only => true, :protected => true, :auto_validation => false)
|
||||
|
||||
|
@ -157,7 +156,6 @@ module CouchRest
|
|||
write_attribute('updated_at', Time.now)
|
||||
write_attribute('created_at', Time.now) if object.new?
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -191,42 +189,32 @@ module CouchRest
|
|||
|
||||
# defines the getter for the property (and optional aliases)
|
||||
def create_property_getter(property)
|
||||
# meth = property.name
|
||||
class_eval <<-EOS, __FILE__, __LINE__ + 1
|
||||
def #{property.name}
|
||||
read_attribute('#{property.name}')
|
||||
define_method(property.name) do
|
||||
read_attribute(property.name)
|
||||
end
|
||||
EOS
|
||||
|
||||
if ['boolean', TrueClass.to_s.downcase].include?(property.type.to_s.downcase)
|
||||
class_eval <<-EOS, __FILE__, __LINE__
|
||||
def #{property.name}?
|
||||
value = read_attribute('#{property.name}')
|
||||
define_method("#{property.name}?") do
|
||||
value = read_attribute(property.name)
|
||||
!(value.nil? || value == false)
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
if property.alias
|
||||
class_eval <<-EOS, __FILE__, __LINE__ + 1
|
||||
alias #{property.alias.to_sym} #{property.name.to_sym}
|
||||
EOS
|
||||
alias_method(property.alias, property.name.to_sym)
|
||||
end
|
||||
end
|
||||
|
||||
# defines the setter for the property (and optional aliases)
|
||||
def create_property_setter(property)
|
||||
property_name = property.name
|
||||
class_eval <<-EOS
|
||||
def #{property_name}=(value)
|
||||
write_attribute('#{property_name}', value)
|
||||
name = property.name
|
||||
|
||||
define_method("#{name}=") do |value|
|
||||
write_attribute(name, value)
|
||||
end
|
||||
EOS
|
||||
|
||||
if property.alias
|
||||
class_eval <<-EOS
|
||||
alias #{property.alias.to_sym}= #{property_name.to_sym}=
|
||||
EOS
|
||||
alias_method "#{property.alias}=", "#{name}="
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue