acts_as_inheritable 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/acts_as_inheritable.rb +4 -3
- data/lib/acts_as_inheritable/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c22fde745dd8537cd5163ee6889ae36da28c38b
|
4
|
+
data.tar.gz: f53988647a6dbb2d2d921ad26d793aa59d15118e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a90d7ba4eb931146859e04bef3b333dfdef7b8933b8f01bc80ab8ba332b792674fb91261ba3cc22bf3bb1cc84f9a63386f2b72c1fb8b4e0fc0e288dbc073767e
|
7
|
+
data.tar.gz: 46d59ea111cca4b0388c8be57384f8b5992977f11b9f66db67b7121c8c9e6eef5bdfd518da3716fb9d6b8051bfe0426240c7b579eec288c902921e0742fcedd7
|
data/lib/acts_as_inheritable.rb
CHANGED
@@ -20,7 +20,7 @@ module ActsAsInheritable
|
|
20
20
|
# relations defined on `INHERITABLE_ASSOCIATIONS`. For each instance on
|
21
21
|
# each relation it re-creates it.
|
22
22
|
def inherit_relations(model_parent = send(:parent), current = self)
|
23
|
-
if model_parent && model_parent.class.method_defined?(:inheritable_configuration)
|
23
|
+
if model_parent && model_parent.class.method_defined?(:inheritable_configuration) && model_parent.class::inheritable_configuration[:associations]
|
24
24
|
model_parent.class::inheritable_configuration[:associations].each do |relation|
|
25
25
|
parent_relation = model_parent.send(relation)
|
26
26
|
relation_instances = parent_relation.respond_to?(:each) ? parent_relation : [parent_relation].compact
|
@@ -35,8 +35,9 @@ module ActsAsInheritable
|
|
35
35
|
new_relation = relation_instance.dup
|
36
36
|
belongs_to_associations_names = model_parent.class.reflect_on_all_associations(:belongs_to).collect(&:name)
|
37
37
|
saved =
|
38
|
+
# Is a `belongs_to` association
|
38
39
|
if belongs_to_associations_names.include?(relation.to_sym)
|
39
|
-
#
|
40
|
+
# You can define your own 'dup' method with a `duplicate!` signature
|
40
41
|
new_relation = relation_instance.duplicate! if relation_instance.respond_to?(:duplicate!)
|
41
42
|
current.send("#{relation}=", new_relation)
|
42
43
|
current.save
|
@@ -70,7 +71,7 @@ module ActsAsInheritable
|
|
70
71
|
end
|
71
72
|
|
72
73
|
def inherit_attributes(force = false, not_force_for=[])
|
73
|
-
if has_parent?
|
74
|
+
if has_parent? && self.class.inheritable_configuration[:attributes]
|
74
75
|
# Attributes
|
75
76
|
self.class.inheritable_configuration[:attributes].each do |attribute|
|
76
77
|
current_val = send(attribute)
|