Module: ActsAs::ClassMethods

Defined in:
lib/acts_as.rb

Instance Method Summary collapse

Instance Method Details

#acts_as(association, type = :belongs_to, with: [], prefix: [], **options) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/acts_as.rb', line 23

def acts_as(association, type = :belongs_to, with: [], prefix: [], **options)
  type == :belongs_to ? belongs_to(association, **options) : has_one(association, **options)
  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
  end
end

#acts_as_fieldsObject



33
34
35
# File 'lib/acts_as.rb', line 33

def acts_as_fields
  @acts_as_fields ||= {}
end