orthoses-rails 1.4.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/orthoses/rails/templates/rails.rake +1 -1
- data/lib/orthoses/active_record/persistence.rb +47 -0
- data/lib/orthoses/active_record/scope.rb +2 -2
- data/lib/orthoses/active_record.rb +1 -0
- data/lib/orthoses/active_support/time_with_zone.rb +17 -3
- data/lib/orthoses/rails/application.rb +1 -0
- data/lib/orthoses/rails/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be001c52b4529ffa0f6f8bcd63b6a5870e2ad0074fe7165470d30a53f2cbdae2
|
4
|
+
data.tar.gz: babc339ee1f2d25c9379c6581d51d390de18d4b62b4820f506fad8eab8906a14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cf6f00f7da35d259fd62cdc2a13379ccc13a7026c99602d9bb12626cf61b2082a702dc1ee53fd738a164082d62527bdc0526fdb3d01a582e156059cdaa42262
|
7
|
+
data.tar.gz: ccff6c8675c6125ce0c44f63b5e9b8727b439d33314bbafcc9c9dc736825beca6f5a1b6bb554e9f4bbaa2f5e46a8665ba403f782b139456d9d75514af90b65f0
|
@@ -22,7 +22,7 @@ namespace :orthoses do
|
|
22
22
|
# By using this middleware, you can add the capability
|
23
23
|
# to generate type information from YARD documentation.
|
24
24
|
# use Orthoses::YARD,
|
25
|
-
# parse: ['{app
|
25
|
+
# parse: ['{app,lib}/**/*.rb']
|
26
26
|
|
27
27
|
# You can load hand written RBS.
|
28
28
|
# use Orthoses::LoadRBS,
|
@@ -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
|
@@ -47,9 +47,9 @@ module Orthoses
|
|
47
47
|
when :key
|
48
48
|
res << "?#{name}: untyped"
|
49
49
|
when :rest
|
50
|
-
res << "*untyped
|
50
|
+
res << "*untyped"
|
51
51
|
when :keyrest
|
52
|
-
res << "**untyped
|
52
|
+
res << "**untyped"
|
53
53
|
when :block
|
54
54
|
block = " { (*untyped) -> untyped }"
|
55
55
|
else
|
@@ -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,12 +28,26 @@ module Orthoses
|
|
28
28
|
-
|
29
29
|
])
|
30
30
|
|
31
|
-
TIME_MODULES = [
|
31
|
+
TIME_MODULES = Set.new([
|
32
32
|
TypeName("::Time"),
|
33
33
|
TypeName("::DateAndTime::Zones"),
|
34
34
|
TypeName("::DateAndTime::Calculations"),
|
35
35
|
TypeName("::DateAndTime::Compatibility")
|
36
|
-
]
|
36
|
+
])
|
37
|
+
|
38
|
+
NONEED_METHODS = Set.new(%i[
|
39
|
+
freeze
|
40
|
+
hash
|
41
|
+
eql?
|
42
|
+
method_missing
|
43
|
+
respond_to?
|
44
|
+
respond_to_missing?
|
45
|
+
is_a?
|
46
|
+
marshal_dump
|
47
|
+
marshal_load
|
48
|
+
to_json
|
49
|
+
< > <= >=
|
50
|
+
])
|
37
51
|
|
38
52
|
def filter_decl(time_with_zone_store)
|
39
53
|
writer = RBS::Writer.new(out: StringIO.new)
|
@@ -68,7 +82,7 @@ module Orthoses
|
|
68
82
|
builder = RBS::DefinitionBuilder.new(env: env.resolve_type_names)
|
69
83
|
twz_methods = builder.build_instance(type_name_time_with_zone).methods
|
70
84
|
builder.build_instance(type_name_time).methods.each do |sym, definition_method|
|
71
|
-
next if
|
85
|
+
next if NONEED_METHODS.include?(sym)
|
72
86
|
next if !definition_method.public?
|
73
87
|
|
74
88
|
# delegate to ::Time method
|
@@ -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
|
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.
|
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:
|
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.
|
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
|