foobara-active-record-type 0.0.4 → 0.0.6
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c68604cfe7a45eebcd95e02929f5756dbc0c703547f6deb9c0a7adb940cb938e
|
4
|
+
data.tar.gz: 507df2c192c22ce5f58514314569cfe1314c24a35a0ded7ca62f020d6a3def3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd16b65c7084969996655dd9bd24ed93c2481c80f1c17465d0b97f7b920cd6f30b007fe07c316037d1c91ad77921d4482c89b44988822767ed77e8056eb1601a
|
7
|
+
data.tar.gz: 3f9963f87e6708158528ce25cd38544c37c7274c4d6b80e866afba080748e2794859b51097d871702a0ef13d88a8c8faf2796f6fcaca1896f18dd0e4bc035993
|
data/CHANGELOG.md
CHANGED
@@ -19,7 +19,8 @@ module Foobara
|
|
19
19
|
|
20
20
|
BuiltinTypes.install_type_declaration_extensions_for(ExtendActiveRecordTypeDeclaration)
|
21
21
|
|
22
|
-
ActiveRecord::Base.include
|
22
|
+
ActiveRecord::Base.include ModelAttributeHelpers::Concerns::AttributeHelpers
|
23
|
+
ActiveRecord::Base.include ActiveRecordFoobaraMethods
|
23
24
|
end
|
24
25
|
|
25
26
|
def reset_all
|
@@ -1,14 +1,48 @@
|
|
1
|
-
module
|
2
|
-
|
1
|
+
module Foobara
|
2
|
+
module ActiveRecordType
|
3
|
+
module ActiveRecordFoobaraMethods
|
4
|
+
extend ActiveSupport::Concern
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
+
class_methods do
|
7
|
+
attr_accessor :foobara_type, :foobara_attributes_type
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
# TODO: implement this or figure out how to re-use the methods from Entity/Model
|
10
|
+
def foobara_associations
|
11
|
+
{}
|
12
|
+
end
|
13
|
+
|
14
|
+
def foobara_primary_key_attribute
|
15
|
+
primary_key
|
16
|
+
end
|
17
|
+
|
18
|
+
def foobara_primary_key_type
|
19
|
+
return @foobara_primary_key_type if @foobara_primary_key_type
|
20
|
+
|
21
|
+
domain = foobara_type.foobara_domain
|
22
|
+
declaration = Foobara::ActiveRecordType.column_name_to_foobara_type_declaration(self, primary_key)
|
23
|
+
@foobara_primary_key_type = domain.foobara_type_from_declaration(declaration)
|
24
|
+
end
|
25
|
+
|
26
|
+
def foobara_attributes_for_create(...)
|
27
|
+
TypeDeclarations::Attributes.reject(super, :created_at, :updated_at)
|
28
|
+
end
|
29
|
+
|
30
|
+
def foobara_attributes_for_update(...)
|
31
|
+
TypeDeclarations::Attributes.reject(super, :created_at, :updated_at)
|
32
|
+
end
|
33
|
+
|
34
|
+
def foobara_attributes_for_aggregate_update(...)
|
35
|
+
TypeDeclarations::Attributes.reject(super, :created_at, :updated_at)
|
36
|
+
end
|
37
|
+
|
38
|
+
def foobara_attributes_for_atom_update(...)
|
39
|
+
TypeDeclarations::Attributes.reject(super, :created_at, :updated_at)
|
40
|
+
end
|
41
|
+
|
42
|
+
def foobara_attributes_for_find_by(...)
|
43
|
+
TypeDeclarations::Attributes.reject(super, :created_at, :updated_at)
|
44
|
+
end
|
45
|
+
end
|
10
46
|
end
|
11
47
|
end
|
12
48
|
end
|
13
|
-
|
14
|
-
ActiveRecord::Base.include ActiveRecordFoobaraMethods
|
@@ -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.6
|
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
|