orthoses-rails 1.3.0 → 1.5.0
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 +4 -4
- data/lib/generators/orthoses/rails/templates/rails.rake +1 -1
- data/lib/orthoses/action_mailer/base.rb +85 -0
- data/lib/orthoses/action_mailer.rb +3 -0
- data/lib/orthoses/active_model/attributes.rb +10 -1
- data/lib/orthoses/active_record/generated_attribute_methods.rb +18 -5
- data/lib/orthoses/active_record/scope.rb +11 -3
- data/lib/orthoses/active_support/concern.rb +1 -1
- data/lib/orthoses/active_support/time_with_zone.rb +17 -3
- data/lib/orthoses/rails/application.rb +2 -0
- data/lib/orthoses/rails/version.rb +1 -1
- data/lib/orthoses/rails.rb +1 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5819282d03a6e3fe410434be4dac07eed3fff60677d013c37ce268c7a259e9fa
|
4
|
+
data.tar.gz: c8a9a445d6e629057b1db47ad08b5472cb4456bc8454071c9ef711e0d10ef100
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd864af949021445b9780e5d95282447e391b0099b90121ece4d58278944ab06264dfeaa25134801386f6e1c7629053d32c6b346d3acde0e1946a004bd3b0c6d
|
7
|
+
data.tar.gz: 72bcdf7904a00596006d405edadbd2fd9d4fe8d1f3c7d6bb8c2929600fff6f1b996ed574a69f1666de504fb27393af0afa2dbd98a055f4dc984d2d8c66024283
|
@@ -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,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Orthoses
|
4
|
+
module ActionMailer
|
5
|
+
class Base
|
6
|
+
def initialize(loader)
|
7
|
+
@loader = loader
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
@loader.call.tap do |store|
|
12
|
+
::ActionMailer::Base.descendants.each do |mailer_class|
|
13
|
+
base_name = Utils.module_name(mailer_class) or next
|
14
|
+
content = store[base_name]
|
15
|
+
mailer_class.action_methods.each do |action_method|
|
16
|
+
method_object = mailer_class.instance_method(action_method)
|
17
|
+
parameters = method_parameters_to_rbs_method_type(method_object).to_s.gsub(' -> untyped', '')
|
18
|
+
content << "def self.#{action_method}: #{parameters} -> ::ActionMailer::MessageDelivery"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def method_parameters_to_rbs_method_type(method_object)
|
27
|
+
required_positionals = []
|
28
|
+
optional_positionals = []
|
29
|
+
rest_positionals = nil
|
30
|
+
trailing_positionals = []
|
31
|
+
required_keywords = {}
|
32
|
+
optional_keywords = {}
|
33
|
+
rest_keywords = nil
|
34
|
+
requireds = required_positionals
|
35
|
+
block = nil
|
36
|
+
untyped = RBS::Types::Bases::Any.new(location: nil)
|
37
|
+
|
38
|
+
method_object.parameters.each do |kind, name|
|
39
|
+
case kind
|
40
|
+
when :req
|
41
|
+
requireds << ::RBS::Types::Function::Param.new(name: name, type: untyped)
|
42
|
+
when :opt
|
43
|
+
requireds = trailing_positionals
|
44
|
+
optional_positionals << ::RBS::Types::Function::Param.new(name: name, type: untyped)
|
45
|
+
when :rest
|
46
|
+
requireds = trailing_positionals
|
47
|
+
name = nil if name == :*
|
48
|
+
rest_positionals = ::RBS::Types::Function::Param.new(name: name, type: untyped)
|
49
|
+
when :keyreq
|
50
|
+
required_keywords[name] = ::RBS::Types::Function::Param.new(name: nil, type: untyped)
|
51
|
+
when :key
|
52
|
+
optional_keywords[name] = ::RBS::Types::Function::Param.new(name: nil, type: untyped)
|
53
|
+
when :keyrest
|
54
|
+
rest_keywords = ::RBS::Types::Function::Param.new(name: name, type: untyped)
|
55
|
+
when :block
|
56
|
+
block = RBS::Types::Block.new(
|
57
|
+
type: RBS::Types::Function.empty(untyped).update(rest_positionals: RBS::Types::Function::Param.new(name: nil, type: untyped)),
|
58
|
+
required: true,
|
59
|
+
self_type: nil
|
60
|
+
)
|
61
|
+
else
|
62
|
+
raise "bug"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
function = ::RBS::Types::Function.new(
|
67
|
+
required_positionals: required_positionals,
|
68
|
+
optional_positionals: optional_positionals,
|
69
|
+
rest_positionals: rest_positionals,
|
70
|
+
trailing_positionals: trailing_positionals,
|
71
|
+
required_keywords: required_keywords,
|
72
|
+
optional_keywords: optional_keywords,
|
73
|
+
rest_keywords: rest_keywords,
|
74
|
+
return_type: untyped,
|
75
|
+
)
|
76
|
+
::RBS::MethodType.new(
|
77
|
+
location: nil,
|
78
|
+
type_params: [],
|
79
|
+
type: function,
|
80
|
+
block: block
|
81
|
+
)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -33,7 +33,16 @@ module Orthoses
|
|
33
33
|
attribute.captures.each do |capture|
|
34
34
|
receiver_name = Utils.module_name(capture.method.receiver) or next
|
35
35
|
name = capture.argument[:name]
|
36
|
-
|
36
|
+
active_model_version = Gem::Version.new(::ActiveModel::VERSION::STRING)
|
37
|
+
cast_type =
|
38
|
+
if active_model_version >= Gem::Version.new('7.1')
|
39
|
+
# https://github.com/rails/rails/commit/608cbfae36b125d7962b7ed9083c9e9e6ce70b88
|
40
|
+
capture.argument[:*].first
|
41
|
+
elsif active_model_version >= Gem::Version.new('7.0')
|
42
|
+
capture.argument[:cast_type]
|
43
|
+
else
|
44
|
+
capture.argument[:type]
|
45
|
+
end
|
37
46
|
|
38
47
|
return_type = DEFAULT_TYPES[cast_type] || 'untyped'
|
39
48
|
|
@@ -4,8 +4,6 @@ module Orthoses
|
|
4
4
|
module ActiveRecord
|
5
5
|
class GeneratedAttributeMethods
|
6
6
|
TARGET_TYPE_MAP = {
|
7
|
-
"attribute" => "() -> %<type>s",
|
8
|
-
"attribute=" => "(%<type>s) -> %<type>s",
|
9
7
|
"attribute?" => "() -> bool",
|
10
8
|
"attribute_before_last_save" => "() -> %<opt>s",
|
11
9
|
"attribute_before_type_cast" => "() -> %<type>s",
|
@@ -50,13 +48,14 @@ module Orthoses
|
|
50
48
|
opt = "#{req}?"
|
51
49
|
type = col.null ? opt : req
|
52
50
|
|
53
|
-
|
54
|
-
|
51
|
+
lines << "attr_accessor #{name}: #{type}"
|
52
|
+
attribute_method_patterns(::ActiveRecord::Base).each do |matcher|
|
53
|
+
tmpl = TARGET_TYPE_MAP[matcher.proxy_target] or next
|
55
54
|
lines << "def #{matcher.method_name(name)}: #{tmpl % {type: type, opt: opt}}"
|
56
55
|
end
|
57
56
|
end
|
58
57
|
klass.attribute_aliases.each do |alias_name, column_name|
|
59
|
-
::ActiveRecord::Base.
|
58
|
+
attribute_method_patterns(::ActiveRecord::Base).each do |matcher|
|
60
59
|
lines << "alias #{matcher.method_name(alias_name)} #{matcher.method_name(column_name)}"
|
61
60
|
end
|
62
61
|
end
|
@@ -69,6 +68,20 @@ module Orthoses
|
|
69
68
|
end
|
70
69
|
end
|
71
70
|
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def attribute_method_patterns(const)
|
75
|
+
if const.respond_to?(:attribute_method_patterns)
|
76
|
+
const.attribute_method_patterns
|
77
|
+
else
|
78
|
+
const.attribute_method_matchers.each do |matcher|
|
79
|
+
def matcher.proxy_target
|
80
|
+
target
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
72
85
|
end
|
73
86
|
end
|
74
87
|
end
|
@@ -20,7 +20,7 @@ module Orthoses
|
|
20
20
|
name = capture.argument[:name]
|
21
21
|
body = capture.argument[:body]
|
22
22
|
|
23
|
-
definition = "#{name}: #{parameters_to_type(body
|
23
|
+
definition = "#{name}: #{parameters_to_type(parameters(body))} -> #{base_name}::ActiveRecord_Relation"
|
24
24
|
store[base_name] << "def self.#{definition}"
|
25
25
|
store["#{base_name}::GeneratedRelationMethods"].header = "module #{base_name}::GeneratedRelationMethods"
|
26
26
|
store["#{base_name}::GeneratedRelationMethods"] << "def #{definition}"
|
@@ -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
|
@@ -58,6 +58,14 @@ module Orthoses
|
|
58
58
|
end
|
59
59
|
"(#{res.join(", ")})#{block}"
|
60
60
|
end
|
61
|
+
|
62
|
+
def parameters(body)
|
63
|
+
if body.respond_to?(:to_proc)
|
64
|
+
body.to_proc.parameters
|
65
|
+
else
|
66
|
+
body.method(:call).parameters
|
67
|
+
end
|
68
|
+
end
|
61
69
|
end
|
62
70
|
end
|
63
71
|
end
|
@@ -36,7 +36,7 @@ module Orthoses
|
|
36
36
|
def members_prototype_of(mod_name)
|
37
37
|
mod = Object.const_get(mod_name)
|
38
38
|
runtime = ::RBS::Prototype::Runtime.new(patterns: nil, env: nil, merge: false)
|
39
|
-
type_name =
|
39
|
+
type_name = TypeName(mod_name)
|
40
40
|
[].tap do |members|
|
41
41
|
runtime.generate_methods(mod, type_name, members)
|
42
42
|
end
|
@@ -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
|
data/lib/orthoses/rails.rb
CHANGED
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.5.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-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: orthoses
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.13'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.13'
|
27
27
|
description: Orthoses middleware collection for Ruby on Rails
|
28
28
|
email:
|
29
29
|
- co000ri@gmail.com
|
@@ -37,6 +37,8 @@ files:
|
|
37
37
|
- lib/generators/orthoses/rails/install_generator.rb
|
38
38
|
- lib/generators/orthoses/rails/templates/rails.rake
|
39
39
|
- lib/orthoses-rails.rb
|
40
|
+
- lib/orthoses/action_mailer.rb
|
41
|
+
- lib/orthoses/action_mailer/base.rb
|
40
42
|
- lib/orthoses/active_model.rb
|
41
43
|
- lib/orthoses/active_model/attributes.rb
|
42
44
|
- lib/orthoses/active_model/has_secure_password.rb
|
@@ -89,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
91
|
- !ruby/object:Gem::Version
|
90
92
|
version: '0'
|
91
93
|
requirements: []
|
92
|
-
rubygems_version: 3.
|
94
|
+
rubygems_version: 3.5.3
|
93
95
|
signing_key:
|
94
96
|
specification_version: 4
|
95
97
|
summary: Orthoses middleware collection for Ruby on Rails
|