foobara-active-record-type 0.0.4 → 0.0.5

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
  SHA256:
3
- metadata.gz: 1328ea690e597739be16596f51e9b71c289486409d87f6e005e4a84c47fc413b
4
- data.tar.gz: f02618973852ed64a501b8ec4cde0872932c21a53aa3ae6678b27e71be4476b2
3
+ metadata.gz: be73fbca7fffeee0f67d261c388d9389c98220d6db6748a3ba349e67d210567c
4
+ data.tar.gz: af657447cb5eddd2722cd3b30940e721d91d4357c64ed6e78485cf9934567705
5
5
  SHA512:
6
- metadata.gz: 9f2901fa9461fcecd6adbf4bd8506e952d657d946d5e8b6a012a8df1e7ea9460b72416fd4e321e1e8108c21e383ed1c1d808077eebbc38d431a968bdd7ac17a3
7
- data.tar.gz: 9d6b34ce44b69da4e20cb8245eb09886b7d5af88ecef493b236c081c7948250822b3e740ab09a790934d9ec86825bb6f65e5be58684264adbbf3fa3851c1c7e2
6
+ metadata.gz: 3a9a10892d969e0a6eb51dc5a34e57bb056f3ec16a1499fa16545b1bcfd5cebb9d4f140d66921d85107e1c7d83742c5890fd9d4373ad2a094d71cb235e309171
7
+ data.tar.gz: 06ec78753cf3bfff0e476b8b276f2f4d6e933a8fa4a6b0c62161a2a4e26470eb838f4528b44fccd7ecdb8c03917385d34b7c777171bc767ec142cc2c3613025f
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ## [0.0.4] - 2025-01-21
1
+ ## [0.0.5] - 2025-01-21
2
2
 
3
3
  - Make use of ModelAttributeHelpers
4
4
 
@@ -8,6 +8,18 @@ module ActiveRecordFoobaraMethods
8
8
  def foobara_associations
9
9
  {}
10
10
  end
11
+
12
+ def foobara_primary_key_attribute
13
+ primary_key
14
+ end
15
+
16
+ def foobara_primary_key_type
17
+ return @foobara_primary_key_type if @foobara_primary_key_type
18
+
19
+ domain = foobara_type.foobara_domain
20
+ declaration = Foobara::ActiveRecordType.column_name_to_foobara_type_declaration(self, primary_key)
21
+ @foobara_primary_key_type = domain.foobara_type_from_declaration(declaration)
22
+ end
11
23
  end
12
24
  end
13
25
 
@@ -0,0 +1,36 @@
1
+ module Foobara
2
+ module ActiveRecordType
3
+ class << self
4
+ def column_name_to_foobara_type_declaration(active_record_class, name)
5
+ column = column_from_name(active_record_class, name)
6
+ column_to_foobara_type_declaration(column)
7
+ end
8
+
9
+ def column_to_foobara_type_declaration(column)
10
+ column_type = column.sql_type_metadata.type
11
+
12
+ type_declaration = case column_type
13
+ when :integer, :string, :datetime
14
+ column_type
15
+ else
16
+ # :nocov:
17
+ raise ArgumentError, "Not sure how to convert #{column_type} to a foobara type symbol"
18
+ # :nocov:
19
+ end
20
+
21
+ # defaults and required will be handled further up
22
+ if column.null
23
+ { type: type_declaration, allow_nil: true }
24
+ else
25
+ type_declaration
26
+ end
27
+ end
28
+
29
+ def column_from_name(active_record_class, name)
30
+ active_record_class.columns.find do |column|
31
+ column.name == name
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -28,23 +28,7 @@ module Foobara
28
28
  end
29
29
 
30
30
  def column_to_foobara_type_declaration(column)
31
- column_type = column.sql_type_metadata.type
32
-
33
- type_declaration = case column_type
34
- when :integer, :string, :datetime
35
- column_type
36
- else
37
- # :nocov:
38
- raise ArgumentError, "Not sure how to convert #{column_type} to a foobara type symbol"
39
- # :nocov:
40
- end
41
-
42
- # defaults and required will be handled further up
43
- if column.null
44
- { type: type_declaration, allow_nil: true }
45
- else
46
- type_declaration
47
- end
31
+ ActiveRecordType.column_to_foobara_type_declaration(column)
48
32
  end
49
33
 
50
34
  def active_record_class_to_attributes_declaration(active_record_class)
@@ -74,9 +58,7 @@ module Foobara
74
58
  end
75
59
 
76
60
  def column_from_name(active_record_class, name)
77
- active_record_class.columns.find do |column|
78
- column.name == name
79
- end
61
+ ActiveRecordType.column_from_name(active_record_class, name)
80
62
  end
81
63
 
82
64
  def priority
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-active-record-type
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-21 00:00:00.000000000 Z
10
+ date: 2025-01-22 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activerecord
@@ -50,6 +50,7 @@ files:
50
50
  - lib/foobara/active_record_type.rb
51
51
  - src/active_record_foobara_methods.rb
52
52
  - src/active_record_thunk.rb
53
+ - src/active_record_type.rb
53
54
  - src/casters/hash.rb
54
55
  - src/casters/primary_key.rb
55
56
  - src/extend_active_record_type_declaration.rb