inherited-attributes 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -0
- data/lib/inherited/attributes/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: c60cd7d343f1a3630f01bd9325ea53f7bb416fe3
|
4
|
+
data.tar.gz: 30f9fcc12b707f73aeca9a34625252a71fadf17e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4929e013230680eb42e7d9b1499428222c219f4cd77793cd968ac84d6364c5b9f9f03781f2f955296478742bd23e909e037eadf63c42f5331ed15a81ac3c4553
|
7
|
+
data.tar.gz: 9138207936dd215a2b4e2e05c0574d0d7eaf6d2b174c3d74338daafa658d2873ef32ab3eeaf916f982e094b720609c8e589b462e0545b85bb1f5b6eeec610c07
|
data/README.md
CHANGED
@@ -22,6 +22,19 @@ class Node < ActiveRecord::Base
|
|
22
22
|
# integers: '<number>'
|
23
23
|
# enumerations: '"<name of the enum>"'
|
24
24
|
inherited_attribute :location, :default => '"Saint Louis"'
|
25
|
+
|
26
|
+
# Has-one relationships can also be inherited.
|
27
|
+
# With delegation, you can expose attributes on the effective or inherited account
|
28
|
+
# Or you can use the effective_account to get the inherited object
|
29
|
+
has_one :account
|
30
|
+
inherited_attribute :account
|
31
|
+
delegate :name, :to => :account, :prefix => true, :allow_nil => true
|
32
|
+
delegate :name, :to => :effective_account, :prefix => true, :allow_nil => true
|
33
|
+
delegate :name, :to => :inherited_account, :prefix => true, :allow_nil => true
|
34
|
+
end
|
35
|
+
|
36
|
+
class Account < ActiveRecord::Base
|
37
|
+
belongs_to :node
|
25
38
|
end
|
26
39
|
```
|
27
40
|
|
@@ -65,6 +78,19 @@ root.inherited_location # 'Saint Louis' -- using the default value
|
|
65
78
|
child.inherited_location # 'Saint Louis' -- Inherited from root
|
66
79
|
grandchild.inherited_location # 'Boston' -- Inherited from child
|
67
80
|
|
81
|
+
# ------------------------------------------------------------------------------
|
82
|
+
# Inherited Has-One relationships and attributes
|
83
|
+
# ------------------------------------------------------------------------------
|
84
|
+
child.create_account(:name => "Cash")
|
85
|
+
|
86
|
+
root.effective_account_name # nil
|
87
|
+
child.effective_account_name # 'Cash'
|
88
|
+
grandchild.effective_account_name # 'Cash' -- Inherited from child
|
89
|
+
|
90
|
+
root.effective_account # nil
|
91
|
+
child.effective_account # <#<Account:0x007fb561759b58 id: 1, name: "Cash", node_id: 2>
|
92
|
+
grandchild.effective_account # <#<Account:0x007fb561759b58 id: 1, name: "Cash", node_id: 2>
|
93
|
+
|
68
94
|
```
|
69
95
|
|
70
96
|
## Installation
|