Permalink
Browse files

No commit message

  • Loading branch information...
1 parent 62e5a8b commit 01d14be53f76317ec2b6e6efc5f946fe1c4c0dfd @stephencelis stephencelis committed Jan 11, 2010
Showing with 4 additions and 7 deletions.
  1. +4 −7 miniskirt.rb
View
@@ -17,17 +17,14 @@ def define(name)
end
def build(name, attrs = {})
- name = name.to_s and (mod = name.classify.constantize).new do |record|
+ (name, n = name.to_s) and (m = name.classify.constantize).new do |rec|
attrs.stringify_keys!.reverse_update(@@factories[name]).each do |k, v|
- record.send "#{k}=", case v when String # Sequence and interpolate.
- v.sub(/%\d*d/) { |n| n % @n ||= mod.maximum(:id).to_i + 1 } %
- attrs % @n
- when Proc then v.call(record) else v
+ rec.send "#{k}=", case v when String # Sequence and interpolate.
+ v.sub(/%\d*d/) {|d| d % n ||= m.maximum(:id).to_i + 1} % attrs % n
+ when Proc then v.call(rec) else v
end
end
end
- ensure
- @n = nil
end
def create(name, attrs = {})

0 comments on commit 01d14be

Please sign in to comment.