lib/extend_at.rb in extend_at-0.0.1 vs lib/extend_at.rb in extend_at-0.0.2
- old
+ new
@@ -78,11 +78,11 @@
assign_attributes_eval = "
# Rewrite the mass assignment method because we need to accept write code like User.new :config_born => 10.years.ago
def assign_attributes(attributes = nil, options = {})
attributes.each_pair do |key, value|
if key.to_s =~ /^#{column_name}_/
- rb = \"#{column_name}.\#\{key.to_s.gsub(/^#{column_name}_/,'')\} = value\"
+ rb = \"self.#{column_name}.\#\{key.to_s.gsub(/^#{column_name}_/,'')\} = value\"
eval rb, binding
end
end
attributes.delete_if do |key,value|
key.to_s =~ /^#{column_name}_/
@@ -91,21 +91,22 @@
end
# Return the value of <<attributes>> methods like <column name>_<extended column name>
def [](column)
if column.to_s =~ /^#{column_name}_[a-zA-Z_][a-zA-Z_0-9]*\=?$/
- rb = \"#{column_name}.\#\{column.to_s.gsub(/^#{column_name}_/,'')\}\"
+ rb = \"self.#{column_name}.\#\{column.to_s.gsub(/^#{column_name}_/,'').gsub(/\=$/, '')\}\"
eval rb, binding
else
super
end
end
# Write the value of <<attributes>> methods like <column name>_<extended column name>
def []=(column, value)
if column.to_s =~ /^#{column_name}_[a-zA-Z_][a-zA-Z_0-9]*\=?$/
- rb = \"#{column_name}.\#\{column\} = value\"
+ rb = \"self.#{column_name}.\#\{column.to_s.gsub(/^#{column_name}_/,'').gsub(/\=$/, '')\} = value\"
+ puts \"Evaluando: #\{rb}\"
eval rb, binding
else
super
end
end
@@ -120,10 +121,10 @@
end
# Accept method like <column name>_<extended column name> for read or write
def method_missing(m, *args, &block)
if m.to_s =~ /^#{column_name}_[a-zA-Z_][a-zA-Z_0-9]*\=$/
- rb = \"self.#{column_name}.\#\{m.to_s.gsub(/^#{column_name}_/, '')} = args.first\"
+ rb = \"self.#{column_name}.\#\{m.to_s.gsub(/^#{column_name}_/, '').gsub(/\=$/, '')} = args.first\"
return eval rb, binding
elsif m.to_s =~ /^#{column_name}_[a-zA-Z_][a-zA-Z_0-9]*$/
rb = \"self.#{column_name}.\#\{m.to_s.gsub(/^#{column_name}_/, '')}\"
return eval rb, binding
else
\ No newline at end of file