multi_tabular 0.2.0 → 0.2.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/lib/multi_tabular/helpers.rb +29 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 822715ac774251bb81727fedfc6db648d0ab048e
|
4
|
+
data.tar.gz: c0184f55b76aaebeb6e145d91319eb726d2ad2fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9820d4db1f6349f1f37c51aac1a2e046cfd066a07e350e5b5821171cf5e842887ea3230f12608eb610239f45b7e0373e782ba2115c413480f530fefc07e0ebb9
|
7
|
+
data.tar.gz: 1bccdf0977fff3ae271f7e86aeeb52525b98369dd22e035a9515b4cfc9346bee834cb42996eae3b5025934ccb42f968808dd65d3cdc68683f2ca1aa0f74332cf
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module MultiTabular
|
2
|
+
module Helpers
|
3
|
+
# Allow converting the class name to an assumed foreign key in an associated model's database.
|
4
|
+
# If a different foreign should be used, you can override this method or simply declare the foreign key manually.
|
5
|
+
def self.to_foreign_key(klass)
|
6
|
+
klass.name.underscore.sub('/', '_').singularize << '_id'
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.define_associations(klass, assoc_list)
|
10
|
+
return if assoc_list.nil?
|
11
|
+
assoc_list.each do |assoc|
|
12
|
+
|
13
|
+
assoc[:opts][:foreign_key] ||= to_foreign_key(klass) unless assoc[:opts][:through]
|
14
|
+
|
15
|
+
if assoc[:multiple]
|
16
|
+
klass.has_many assoc[:name], assoc[:opts]
|
17
|
+
else
|
18
|
+
klass.has_one assoc[:name], assoc[:opts]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# for a given class, returns the appropriate symbol
|
24
|
+
# to pass to the ActiveRecord method reflect_on_association
|
25
|
+
def self.reflection_symbol(klass)
|
26
|
+
klass.to_s.gsub(/::/, '_').underscore.to_sym
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_tabular
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Junger
|
@@ -48,6 +48,7 @@ extra_rdoc_files: []
|
|
48
48
|
files:
|
49
49
|
- Gemfile
|
50
50
|
- lib/multi_tabular.rb
|
51
|
+
- lib/multi_tabular/helpers.rb
|
51
52
|
- lib/multi_tabular/references.rb
|
52
53
|
- lib/multi_tabular/super.rb
|
53
54
|
- lib/multi_tabular/version.rb
|