lib/acts_as.rb in acts_as-0.0.3 vs lib/acts_as.rb in acts_as-0.1.0
- old
+ new
@@ -18,12 +18,12 @@
end.keys.first
@association_match && send(@association_match).respond_to?(method)
end
module ClassMethods
- def acts_as(association, type = :belongs_to, with: [], prefix: [], **options)
- type == :belongs_to ? belongs_to(association, **options) : has_one(association, **options)
+ def acts_as(association, with: [], prefix: [], **options)
+ belongs_to(association, **options.merge(autosave: true))
define_method(association) { |*args| super(*args) || send("build_#{association}", *args) }
if (association_class = new.send(association).class).table_exists?
whitelist_and_delegate_fields(association_class, association, prefix, with)
override_method_missing
@@ -58,11 +58,10 @@
attr_accessible *association_fields
attr_accessible *prefix.map { |field| "#{one_association}_#{field}" }
delegate(*(association_fields + association_fields.map { |field| "#{field}=" }), to: one_association)
- #TODO: This feels like a weird place to remember delegated fields
acts_as_fields[one_association] = association_fields + prefix
end
def build_prefix_methods(one_association, prefix)
prefix.each do |field|
@@ -74,6 +73,6 @@
send(one_association).send("#{field}=", *args)
end
end
end
end
-end
\ No newline at end of file
+end