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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: debc03f6def20cff892f28c8dee0e332b4a9021f
4
- data.tar.gz: 764ce557abcb939139c0f822eaebb7c653323910
3
+ metadata.gz: c60cd7d343f1a3630f01bd9325ea53f7bb416fe3
4
+ data.tar.gz: 30f9fcc12b707f73aeca9a34625252a71fadf17e
5
5
  SHA512:
6
- metadata.gz: f7090f1d2f5dde67b3cea7bd60f9cec178476b89869550921d65d0ff6585cbb1b82c32e3cda2d474b2be927e56c9ddc60a99f57c76987590146a4f7b73ddeea0
7
- data.tar.gz: ac622fe4603b0383e10b3e21f308a3d36b1f889f55b3c82271408a42458990807379751f12ea80c3e40c64840dd00bca1280b059f0d02d6b845ea11f1b19a55f
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
@@ -1,5 +1,5 @@
1
1
  module Inherited
2
2
  module Attributes
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inherited-attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Naegle