foobara-active-record-type 0.0.3 → 0.0.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: 3499a493db193b496a20ae4dd0d1dd1d7ad5193701346ee2de9abc397b107ff9
4
- data.tar.gz: 59db77d01419543a0230aecb0d5f49aa6f1ba541bb820d7ffd743ee41211d2ea
3
+ metadata.gz: be73fbca7fffeee0f67d261c388d9389c98220d6db6748a3ba349e67d210567c
4
+ data.tar.gz: af657447cb5eddd2722cd3b30940e721d91d4357c64ed6e78485cf9934567705
5
5
  SHA512:
6
- metadata.gz: a72802f7ae7ef65f5174285ae4dde77f7876b3463ea3d6a69bc7366a91838b5e1a22b94a8c6352b3725755195121855f391a30163378ceb065cfd16c6d9b9622
7
- data.tar.gz: b49ed2b61b22d34e1b0179c841e2deb05ac5b0886fa71826bcb781f1572e6c52323ed729cd2ae7b058d5e078a184fb872e8dff4329fdd8184c557f7ef15332f0
6
+ metadata.gz: 3a9a10892d969e0a6eb51dc5a34e57bb056f3ec16a1499fa16545b1bcfd5cebb9d4f140d66921d85107e1c7d83742c5890fd9d4373ad2a094d71cb235e309171
7
+ data.tar.gz: 06ec78753cf3bfff0e476b8b276f2f4d6e933a8fa4a6b0c62161a2a4e26470eb838f4528b44fccd7ecdb8c03917385d34b7c777171bc767ec142cc2c3613025f
data/CHANGELOG.md CHANGED
@@ -1,10 +1,14 @@
1
- ## [0.0.3]
1
+ ## [0.0.5] - 2025-01-21
2
+
3
+ - Make use of ModelAttributeHelpers
4
+
5
+ ## [0.0.3] - 2025-01-17
2
6
 
3
7
  - Fix problem where the first time a type is declared via an
4
8
  active record class it has a complex declaration hash instead of a simple
5
9
  registered class lookup
6
10
 
7
- ## [0.0.1]
11
+ ## [0.0.1] - 2025-01-03
8
12
 
9
13
  - Release as a gem
10
14
 
@@ -18,6 +18,8 @@ module Foobara
18
18
  )
19
19
 
20
20
  BuiltinTypes.install_type_declaration_extensions_for(ExtendActiveRecordTypeDeclaration)
21
+
22
+ ActiveRecord::Base.include Foobara::ModelAttributeHelpers::Concerns::AttributeHelpers
21
23
  end
22
24
 
23
25
  def reset_all
@@ -3,6 +3,23 @@ module ActiveRecordFoobaraMethods
3
3
 
4
4
  class_methods do
5
5
  attr_accessor :foobara_type, :foobara_attributes_type
6
+
7
+ # TODO: implement this or figure out how to re-use the methods from Entity/Model
8
+ def foobara_associations
9
+ {}
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
6
23
  end
7
24
  end
8
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.3
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-18 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