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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be73fbca7fffeee0f67d261c388d9389c98220d6db6748a3ba349e67d210567c
|
4
|
+
data.tar.gz: af657447cb5eddd2722cd3b30940e721d91d4357c64ed6e78485cf9934567705
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a9a10892d969e0a6eb51dc5a34e57bb056f3ec16a1499fa16545b1bcfd5cebb9d4f140d66921d85107e1c7d83742c5890fd9d4373ad2a094d71cb235e309171
|
7
|
+
data.tar.gz: 06ec78753cf3bfff0e476b8b276f2f4d6e933a8fa4a6b0c62161a2a4e26470eb838f4528b44fccd7ecdb8c03917385d34b7c777171bc767ec142cc2c3613025f
|
data/CHANGELOG.md
CHANGED
@@ -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
|
-
|
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
|
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
|
+
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-
|
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
|