detailed 0.1.0 → 0.1.1
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/README.md +10 -2
- data/lib/detailed.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 773a15233f8c2aa098c2b089ee96566ef1672859
|
4
|
+
data.tar.gz: 091ba6bb5fd11d243004eff35e5d878769328a8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 393aebd0421299e915ce67b13cbdcad929b95f33cd9946d5891baa82306158df692e82e2aadbb5fe9e0a18e4a7c3e76f79be3a2824c8a6e6b54eaa14b70f7b93
|
7
|
+
data.tar.gz: a1a380b74ebc8746609d857d43b1e8bc45d3a73da7fcf690a5cbfe057712500619923483c8dac19b4306ac1c782f9a900b90708d62e7085c508e0282e5cdac08
|
data/README.md
CHANGED
@@ -5,12 +5,14 @@ Compromise between single and multiple table inheritance with ActiveRecord. This
|
|
5
5
|
depend on Rails at all (that's, in fact, how it originated).
|
6
6
|
|
7
7
|
With this gem you can have a table hierarchy like this:
|
8
|
+
|
8
9
|
user (id, type (class), login, password)
|
9
10
|
|- user_client_details (client_id, billing_address, phone_number)
|
10
11
|
|- user_worker_details (worker_id, wage, bank_account)
|
11
12
|
`- user_supplier_details (supplier_id, company_name)
|
12
13
|
|
13
14
|
And models hierarchy like this:
|
15
|
+
|
14
16
|
ActiveRecord::Base
|
15
17
|
|- User
|
16
18
|
| |- Client
|
@@ -21,11 +23,13 @@ And models hierarchy like this:
|
|
21
23
|
`- UserSupplierDetail
|
22
24
|
|
23
25
|
All detail classes would look like this (nothing more is needed):
|
26
|
+
|
24
27
|
UserWorkerDetail < ActiveRecord::Base
|
25
28
|
belongs_to :worker
|
26
29
|
end
|
27
30
|
|
28
31
|
The main class should be in this form:
|
32
|
+
|
29
33
|
class User < ActiveRecord::Base
|
30
34
|
# ... your code here ...
|
31
35
|
|
@@ -33,6 +37,7 @@ The main class should be in this form:
|
|
33
37
|
end
|
34
38
|
|
35
39
|
The subclasses should be in this form:
|
40
|
+
|
36
41
|
class Client < User
|
37
42
|
request_details
|
38
43
|
|
@@ -40,6 +45,7 @@ The subclasses should be in this form:
|
|
40
45
|
end
|
41
46
|
|
42
47
|
To add this package to your environment, add the following line to your Gemfile:
|
48
|
+
|
43
49
|
gem "detailed"
|
44
50
|
|
45
51
|
This gem started from this post on StackExchange: http://stackoverflow.com/a/1634734/3256901 .
|
@@ -48,6 +54,7 @@ This gem started from this post on StackExchange: http://stackoverflow.com/a/163
|
|
48
54
|
Access to detailed properties
|
49
55
|
-----------------------------
|
50
56
|
With the tableset above, we can access our variables directly, like
|
57
|
+
|
51
58
|
client = new Client
|
52
59
|
client.login = "teh1234" # a field of user
|
53
60
|
client.billing_address = "Zgoda 18/2" # a field of user_client_details
|
@@ -55,6 +62,7 @@ With the tableset above, we can access our variables directly, like
|
|
55
62
|
|
56
63
|
Be aware, that you can't issue find/where with extended fields at the current
|
57
64
|
time. You need to resort to the regular:
|
65
|
+
|
58
66
|
Client.find("details_of_client.billing_address" => "Zgoda 18/2")
|
59
67
|
|
60
68
|
|
@@ -111,8 +119,8 @@ Subclasses without details
|
|
111
119
|
Sometimes you are going to subclass the main model without the need for additional
|
112
120
|
fields. This is easy, you just do
|
113
121
|
|
114
|
-
class BasicUser < User
|
115
|
-
end
|
122
|
+
class BasicUser < User
|
123
|
+
end
|
116
124
|
|
117
125
|
No further code needed, detailed won't go into your way.
|
118
126
|
|
data/lib/detailed.rb
CHANGED
@@ -31,7 +31,7 @@ module Detailed
|
|
31
31
|
@subclasses << sc
|
32
32
|
|
33
33
|
class_eval do
|
34
|
-
has_one :"details_of_#{sc.name.tableize}", class_name: "#{self.name}#{sc.name}Detail", foreign_key: "#{sc.name.tableize.singularize}_id" #, inverse_of: "#{sc.name.tableize}"
|
34
|
+
has_one :"details_of_#{sc.name.tableize}", class_name: "#{self.name}#{sc.name}Detail", foreign_key: "#{sc.name.tableize.singularize}_id", autosave: true #, inverse_of: "#{sc.name.tableize}"
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: detailed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcin Łabanowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: An ActiveRecord module giving you the power of multiple table inheritance
|
14
14
|
while still resorting to an API resembling single table inheritance
|