orthoses-rails 1.5.0 → 1.6.0

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: 5819282d03a6e3fe410434be4dac07eed3fff60677d013c37ce268c7a259e9fa
4
- data.tar.gz: c8a9a445d6e629057b1db47ad08b5472cb4456bc8454071c9ef711e0d10ef100
3
+ metadata.gz: be001c52b4529ffa0f6f8bcd63b6a5870e2ad0074fe7165470d30a53f2cbdae2
4
+ data.tar.gz: babc339ee1f2d25c9379c6581d51d390de18d4b62b4820f506fad8eab8906a14
5
5
  SHA512:
6
- metadata.gz: dd864af949021445b9780e5d95282447e391b0099b90121ece4d58278944ab06264dfeaa25134801386f6e1c7629053d32c6b346d3acde0e1946a004bd3b0c6d
7
- data.tar.gz: 72bcdf7904a00596006d405edadbd2fd9d4fe8d1f3c7d6bb8c2929600fff6f1b996ed574a69f1666de504fb27393af0afa2dbd98a055f4dc984d2d8c66024283
6
+ metadata.gz: 5cf6f00f7da35d259fd62cdc2a13379ccc13a7026c99602d9bb12626cf61b2082a702dc1ee53fd738a164082d62527bdc0526fdb3d01a582e156059cdaa42262
7
+ data.tar.gz: ccff6c8675c6125ce0c44f63b5e9b8727b439d33314bbafcc9c9dc736825beca6f5a1b6bb554e9f4bbaa2f5e46a8665ba403f782b139456d9d75514af90b65f0
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Orthoses
4
+ module ActiveRecord
5
+ class Persistence
6
+ def initialize(loader)
7
+ @loader = loader
8
+ end
9
+
10
+ def call
11
+ @loader.call.tap do |store|
12
+ ::ActiveRecord::Base.descendants.each do |klass|
13
+ next if klass.abstract_class?
14
+ base_name = Utils.module_name(klass) or next
15
+
16
+ attributes = klass.columns_hash.map do |key, col|
17
+ req = ActiveRecord.sql_type_to_rbs(col.type)
18
+ opt = "#{req}?"
19
+ [key.to_s, col.null ? opt : req]
20
+ end.to_h
21
+
22
+ klass.attribute_aliases.each do |alias_name, column_name|
23
+ alias_value = attributes[column_name.to_s] or next
24
+ attributes[alias_name.to_s] = alias_value
25
+ end
26
+
27
+ optional_definitions = attributes.map do |name, type|
28
+ "?#{name}: #{type}"
29
+ end.join(", ")
30
+
31
+ class_methods_name = "#{base_name}::ActiveRecord_Persistence_ClassMethods"
32
+ store[base_name] << "extend #{class_methods_name}"
33
+ store[class_methods_name].header = "module #{class_methods_name}"
34
+
35
+ %i[create create! build].each do |method|
36
+ method = <<~RBS
37
+ def #{method}: (#{optional_definitions}, **untyped) ?{ (#{base_name}) -> void } -> #{base_name}
38
+ | (::Array[Hash[Symbol, untyped]]) ?{ (#{base_name}) -> void } -> ::Array[#{base_name}]
39
+ RBS
40
+ store[class_methods_name] << method
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -6,6 +6,7 @@ require_relative 'active_record/enum'
6
6
  require_relative 'active_record/generated_attribute_methods'
7
7
  require_relative 'active_record/has_many'
8
8
  require_relative 'active_record/has_one'
9
+ require_relative 'active_record/persistence'
9
10
  require_relative 'active_record/query_methods'
10
11
  require_relative 'active_record/relation'
11
12
  require_relative 'active_record/scope'
@@ -28,6 +28,7 @@ module Orthoses
28
28
  use Orthoses::ActiveRecord::GeneratedAttributeMethods
29
29
  use Orthoses::ActiveRecord::HasMany
30
30
  use Orthoses::ActiveRecord::HasOne
31
+ use Orthoses::ActiveRecord::Persistence
31
32
  use Orthoses::ActiveRecord::Relation
32
33
  use Orthoses::ActiveRecord::Scope
33
34
  use Orthoses::ActiveRecord::SecureToken
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Orthoses
4
4
  module Rails
5
- VERSION = "1.5.0"
5
+ VERSION = "1.6.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orthoses-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-11 00:00:00.000000000 Z
11
+ date: 2024-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: orthoses
@@ -49,6 +49,7 @@ files:
49
49
  - lib/orthoses/active_record/generated_attribute_methods.rb
50
50
  - lib/orthoses/active_record/has_many.rb
51
51
  - lib/orthoses/active_record/has_one.rb
52
+ - lib/orthoses/active_record/persistence.rb
52
53
  - lib/orthoses/active_record/query_methods.rb
53
54
  - lib/orthoses/active_record/relation.rb
54
55
  - lib/orthoses/active_record/scope.rb
@@ -91,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
92
  - !ruby/object:Gem::Version
92
93
  version: '0'
93
94
  requirements: []
94
- rubygems_version: 3.5.3
95
+ rubygems_version: 3.3.26
95
96
  signing_key:
96
97
  specification_version: 4
97
98
  summary: Orthoses middleware collection for Ruby on Rails