local_model 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32aaa0557b37154955a584e86ddafab8b7dc5dac3731f77edb0817beeb511739
4
- data.tar.gz: 731283ec3e8f5577551247b006d29f919cc22dc5bbef5726ee60e008f19fe35b
3
+ metadata.gz: f853000f33467ac6f85e87035eecfcd676640fc6bbaf05457a61637604c9f005
4
+ data.tar.gz: f33774550c04178eb2083f9a1c008b1d6e548454a9134077a345a822c274fb27
5
5
  SHA512:
6
- metadata.gz: af60390ff697de0be4c0b873af689ce0ad9f8169a883fab25a5b2ff933ce56e3603fa602d76fae1c36f966c71392eb3844c117f6614d228bde7a0c9a5aebc073
7
- data.tar.gz: d1e7e26d09cbd221f29ac75ba885577fa78ed01170aeaf1a9c09501b1046f2824a4a1ac807a2ff22373a8c39a584aba4f749795bdc5e7d5d8ba6f29bda1bbb4d
6
+ metadata.gz: 7a66632adc5f6c61c0f4d2f9153df4af34427e03cb3dccdcef59c6f4f6fabcdada61e7071ec0b3f4a85679830f57f48f120863677d0077826cf1961ddd55d847
7
+ data.tar.gz: 0e38bf60d7b826a97b4b7f7db53740ad3b532cb054dc843eb58f1e4f770cd57b73c915f4ab252d7aeac5b2784192f3d3d32aabd34bce2e6b570ccd09ced43714
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- local_model (0.1.2)
4
+ local_model (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -5,19 +5,29 @@ class LocalModel::Model
5
5
  # yield(SchemaBuilder.new(self))
6
6
  end
7
7
 
8
- def self.belongs_to(association)
9
- association_class_name = LocalModel::Functions.snake_to_camel(association)
10
- association_class_name[0] = association_class_name[0].upcase
11
- association_class_name = namespace_classname(association_class_name)
8
+ def self.belongs_to(association, class_name: nil, foreign_key: nil)
9
+ if class_name.nil?
10
+ association_class_name = LocalModel::Functions.snake_to_camel(association)
11
+ association_class_name[0] = association_class_name[0].upcase
12
+ association_class_name = namespace_classname(association_class_name)
13
+ else
14
+ association_class_name = namespace_classname(class_name)
15
+ end
12
16
  association_class = Object.const_get(association_class_name)
13
17
 
18
+ if foreign_key.nil?
19
+ keyname = "#{association}_id"
20
+ else
21
+ keyname = foreign_key
22
+ end
23
+
14
24
  define_method association do
15
- id = self.send("#{association}_id")
25
+ id = self.send(keyname)
16
26
  association_class.find(id)
17
27
  end
18
28
 
19
29
  define_method "#{association}=" do |association_obj|
20
- self.send("#{association}_id=", association_obj.id)
30
+ self.send("#{keyname}=", association_obj.id)
21
31
  end
22
32
  end
23
33
 
@@ -1,3 +1,3 @@
1
1
  module LocalModel
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: local_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Shute
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-12 00:00:00.000000000 Z
11
+ date: 2021-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler