multi_tabular 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/multi_tabular/helpers.rb +29 -0
  3. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fcc9947c6c1012e9ce4323ea9a229c17f11297d2
4
- data.tar.gz: c1ef6779f525bea94bf34297a0c44ddec2f57ed9
3
+ metadata.gz: 822715ac774251bb81727fedfc6db648d0ab048e
4
+ data.tar.gz: c0184f55b76aaebeb6e145d91319eb726d2ad2fc
5
5
  SHA512:
6
- metadata.gz: 242eff27bd59d336e151e1d32bb4b0583a00d8a717e1d8db83638b7d88dae0a8021113f5c52b5ab8e1d10c9dd7c743403af4fff3c453fe700863bdabe5917966
7
- data.tar.gz: 87902e0b64cdc70963ba7c1c59e58e42c86fbb4947960640a84681fcbe21d29dd1ae2bad34eae9237991742a5e1d383f9724765c4202ba7a17b61ce6edc7e505
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.0
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