Module: ActiveModel::Embedding::Associations::ClassMethods

Defined in:
lib/active_model/embedding/associations.rb

Instance Method Summary collapse

Instance Method Details

#embedded_associationsObject



60
61
62
# File 'lib/active_model/embedding/associations.rb', line 60

def embedded_associations
  class_variable_get :@@embedded_associations
end

#embeds_many(attr_name, class_name: nil, cast_type: nil, collection: nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/active_model/embedding/associations.rb', line 33

def embeds_many(attr_name, class_name: nil, cast_type: nil, collection: nil)
  class_name = cast_type ? nil : class_name || infer_class_name_from(attr_name)

  attribute :"#{attr_name}", :document,
    class_name: class_name,
    cast_type: cast_type,
    collection: collection || true,
    context: self.to_s

  register_embedded_association attr_name

  nested_attributes_for attr_name
end

#embeds_one(attr_name, class_name: nil, cast_type: nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/active_model/embedding/associations.rb', line 47

def embeds_one(attr_name, class_name: nil, cast_type: nil)
  class_name = cast_type ? nil : class_name || infer_class_name_from(attr_name)

  attribute :"#{attr_name}", :document,
    class_name: class_name,
    cast_type: cast_type,
    context: self.to_s

  register_embedded_association attr_name

  nested_attributes_for attr_name
end