lib/sequel/model.rb in sequel-0.0.12 vs lib/sequel/model.rb in sequel-0.0.13
- old
+ new
@@ -193,10 +193,11 @@
model.dataset.filter(primary_key => @pkey).delete
end
FIND_BY_REGEXP = /^find_by_(.*)/.freeze
FILTER_BY_REGEXP = /^filter_by_(.*)/.freeze
+ WRITE_ATTR_REGEXP = /(.*)=$/.freeze
def self.method_missing(m, *args)
Thread.exclusive do
method_name = m.to_s
if method_name =~ FIND_BY_REGEXP
@@ -205,26 +206,18 @@
send(m, *args) if respond_to?(m)
elsif method_name =~ FILTER_BY_REGEXP
c = $1
meta_def(method_name) {|arg| filter(c => arg)}
send(m, *args) if respond_to?(m)
+ elsif method_name =~ WRITE_ATTR_REGEXP
+ self[$1.to_sym] = value
else
- super
+ self[m]
end
end
end
def db; @@db; end
-
- ASSIGN_METHOD_REGEXP = /(.*)=$/.freeze
-
- def method_missing(sym, value = nil)
- if sym.to_s =~ ASSIGN_METHOD_REGEXP
- @values[$1.to_sym] = value
- else
- @values[sym]
- end
- end
def reload
temp = self.class[@pkey]
@values = self.class.dataset.naked[primary_key => @pkey]
end