orthoses-rails 1.0.0 → 1.1.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/README.md +8 -1
- data/lib/generators/orthoses/rails/templates/rails.rake +31 -0
- data/lib/orthoses/active_record/secure_token.rb +28 -0
- data/lib/orthoses/active_record.rb +1 -0
- data/lib/orthoses/active_storage/attached/model.rb +47 -0
- data/lib/orthoses/active_storage.rb +3 -0
- data/lib/orthoses/active_support/aliasing.rb +34 -0
- data/lib/orthoses/active_support/time_with_zone.rb +10 -2
- data/lib/orthoses/active_support.rb +1 -0
- data/lib/orthoses/rails/application.rb +14 -0
- data/lib/orthoses/rails/version.rb +1 -1
- data/lib/orthoses/rails.rb +1 -0
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec337b1da4ecda39f953797824239ede59c536c74da48cc1dbd01e46eed1d2b0
|
4
|
+
data.tar.gz: b146481d3fda9b3568a1593fd05608f09c811e1181356f2e36d2b010c30dd130
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bec23dc332048a010d10a2dc01754b969f76d2dd19bfa4b50393c1a764b3de496a35d018560aca04fe43630de497e900bb580774698bda3073ea33dcbf44bb5
|
7
|
+
data.tar.gz: e2dac22ee12a3bf049a73e5609d4a3ca1693c2dbc851c3bb06256e4566e9adad6c991fa9a60b0aaa7b22d6ea19e0c7cbc65c403cd136669d4c98b58deb7d90e7
|
data/README.md
CHANGED
@@ -5,9 +5,16 @@ Orthoses::Rails automatically generates RBS for methods added by Rails.
|
|
5
5
|
|
6
6
|
## Usage
|
7
7
|
|
8
|
+
If you have never performed rbs collection initialization, you need to do it.
|
9
|
+
|
10
|
+
```
|
11
|
+
$ bundle exec rbs collection init
|
12
|
+
$ bundle exec rbs collection install
|
13
|
+
```
|
14
|
+
|
8
15
|
Build your Rake task for RBS generation.
|
9
16
|
|
10
|
-
```
|
17
|
+
```
|
11
18
|
$ bin/rails generate orthoses:rails:install
|
12
19
|
```
|
13
20
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
namespace :orthoses do
|
2
|
+
task :rails do
|
3
|
+
# Phase to load libraries
|
4
|
+
require Rails.root / "config/application"
|
5
|
+
require 'orthoses/rails'
|
6
|
+
|
7
|
+
# You can choose logger level
|
8
|
+
Orthoses.logger.level = :warn
|
9
|
+
|
10
|
+
# DSL for Orthoses.
|
11
|
+
Orthoses::Builder.new do
|
12
|
+
use Orthoses::CreateFileByName,
|
13
|
+
to: 'sig/orthoses', # Write to this dir. (require)
|
14
|
+
depth: 1, # Group files by module name path depth. (default: nil)
|
15
|
+
rmtree: true # Remove all `to` dir before generation. (default: false)
|
16
|
+
|
17
|
+
# Complement missing const name.
|
18
|
+
use Orthoses::MissingName
|
19
|
+
|
20
|
+
# You can load hand written RBS.
|
21
|
+
# use Orthoses::LoadRBS,
|
22
|
+
# paths: Dir.glob(Rails.root / "sig/hand-written/**/*.rbs")
|
23
|
+
|
24
|
+
# Middleware package for rails application.
|
25
|
+
use Orthoses::Rails::Application
|
26
|
+
|
27
|
+
# Application code loaded here is the target of the analysis.
|
28
|
+
run Orthoses::Rails::Application::Loader.new
|
29
|
+
end.call
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Orthoses
|
4
|
+
module ActiveRecord
|
5
|
+
# def has_secure_token(attribute = :token, length: MINIMUM_TOKEN_LENGTH)
|
6
|
+
class SecureToken
|
7
|
+
def initialize(loader)
|
8
|
+
@loader = loader
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
has_secure_token = CallTracer::Lazy.new
|
13
|
+
store = has_secure_token.trace('ActiveRecord::SecureToken::ClassMethods#has_secure_token') do
|
14
|
+
@loader.call
|
15
|
+
end
|
16
|
+
|
17
|
+
has_secure_token.captures.each do |capture|
|
18
|
+
base_name = Utils.module_name(capture.method.receiver) or next
|
19
|
+
attribute = capture.argument[:attribute]
|
20
|
+
|
21
|
+
store[base_name] << "def regenerate_#{attribute}: () -> bool"
|
22
|
+
end
|
23
|
+
|
24
|
+
store
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -9,6 +9,7 @@ require_relative 'active_record/has_one'
|
|
9
9
|
require_relative 'active_record/query_methods'
|
10
10
|
require_relative 'active_record/relation'
|
11
11
|
require_relative 'active_record/scope'
|
12
|
+
require_relative 'active_record/secure_token'
|
12
13
|
|
13
14
|
module Orthoses
|
14
15
|
module ActiveRecord
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Orthoses
|
4
|
+
module ActiveStorage
|
5
|
+
module Attached
|
6
|
+
# <= 6.0
|
7
|
+
# def has_one_attached(name, dependent: :purge_later)
|
8
|
+
# >= 6.1
|
9
|
+
# def has_one_attached(name, dependent: :purge_later, service: nil, strict_loading: false)
|
10
|
+
class Model
|
11
|
+
def initialize(loader)
|
12
|
+
@loader = loader
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
store = @loader.call
|
17
|
+
|
18
|
+
::ActiveRecord::Base.descendants.each do |base|
|
19
|
+
next if base.abstract_class?
|
20
|
+
next if base.reflect_on_all_attachments.empty?
|
21
|
+
|
22
|
+
base_name = Utils.module_name(base) or next
|
23
|
+
base.reflect_on_all_attachments.each do |reflection|
|
24
|
+
type =
|
25
|
+
case reflection
|
26
|
+
when ::ActiveStorage::Reflection::HasOneAttachedReflection
|
27
|
+
"ActiveStorage::Attached::One"
|
28
|
+
when ::ActiveStorage::Reflection::HasManyAttachedReflection
|
29
|
+
"ActiveStorage::Attached::Many"
|
30
|
+
else
|
31
|
+
"untyped"
|
32
|
+
end
|
33
|
+
name = reflection.name
|
34
|
+
|
35
|
+
store[base_name].tap do |content|
|
36
|
+
content << "def #{name}: () -> #{type}"
|
37
|
+
content << "def #{name}=: (untyped attachable) -> untyped"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
store
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Orthoses
|
4
|
+
module ActiveSupport
|
5
|
+
# def alias_attribute(new_name, old_name)
|
6
|
+
class Aliasing
|
7
|
+
def initialize(loader)
|
8
|
+
@loader = loader
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
alias_attribute = CallTracer::Lazy.new
|
13
|
+
|
14
|
+
store =
|
15
|
+
alias_attribute.trace('Module#alias_attribute') do
|
16
|
+
@loader.call
|
17
|
+
end
|
18
|
+
|
19
|
+
alias_attribute.captures.each do |capture|
|
20
|
+
base_mod_name = Utils.module_name(capture.method.receiver) or next
|
21
|
+
new_name = capture.argument[:new_name]
|
22
|
+
|
23
|
+
content = store[base_mod_name]
|
24
|
+
# TODO: Shold use alias? But, it has risc of undefined method
|
25
|
+
content << "def #{new_name}: () -> untyped"
|
26
|
+
content << "def #{new_name}?: () -> bool"
|
27
|
+
content << "def #{new_name}=: (untyped) -> untyped"
|
28
|
+
end
|
29
|
+
|
30
|
+
store
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -28,6 +28,13 @@ module Orthoses
|
|
28
28
|
-
|
29
29
|
])
|
30
30
|
|
31
|
+
TIME_MODULES = [
|
32
|
+
TypeName("::Time"),
|
33
|
+
TypeName("::DateAndTime::Zones"),
|
34
|
+
TypeName("::DateAndTime::Calculations"),
|
35
|
+
TypeName("::DateAndTime::Compatibility")
|
36
|
+
]
|
37
|
+
|
31
38
|
def filter_decl(time_with_zone_store)
|
32
39
|
writer = RBS::Writer.new(out: StringIO.new)
|
33
40
|
time_with_zone_store.to_decl.members.each do |member|
|
@@ -64,8 +71,9 @@ module Orthoses
|
|
64
71
|
next if twz_methods.has_key?(sym) && !TYPE_MERGE_METHODS.include?(sym)
|
65
72
|
next if !definition_method.public?
|
66
73
|
|
67
|
-
|
68
|
-
|
74
|
+
# delegate to ::Time method
|
75
|
+
definition_method.defs.select! do |type_def|
|
76
|
+
TIME_MODULES.include?(type_def.implemented_in)
|
69
77
|
end
|
70
78
|
next if definition_method.defs.empty?
|
71
79
|
|
@@ -3,6 +3,13 @@
|
|
3
3
|
module Orthoses
|
4
4
|
module Rails
|
5
5
|
class Application
|
6
|
+
class Loader
|
7
|
+
def call
|
8
|
+
::Rails.application.initialize!
|
9
|
+
::Rails.application.eager_load!
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
6
13
|
def initialize(loader)
|
7
14
|
@loader = loader
|
8
15
|
end
|
@@ -11,6 +18,7 @@ module Orthoses
|
|
11
18
|
loader = @loader
|
12
19
|
Orthoses::Builder.new do
|
13
20
|
use Orthoses::ActiveModel::HasSecurePassword
|
21
|
+
|
14
22
|
use Orthoses::ActiveRecord::BelongsTo
|
15
23
|
use Orthoses::ActiveRecord::DelegatedType
|
16
24
|
use Orthoses::ActiveRecord::Enum
|
@@ -19,7 +27,13 @@ module Orthoses
|
|
19
27
|
use Orthoses::ActiveRecord::HasOne
|
20
28
|
use Orthoses::ActiveRecord::Relation
|
21
29
|
use Orthoses::ActiveRecord::Scope
|
30
|
+
use Orthoses::ActiveRecord::SecureToken
|
31
|
+
|
32
|
+
if defined?(::ActiveStorage)
|
33
|
+
use Orthoses::ActiveStorage::Attached::Model
|
34
|
+
end
|
22
35
|
|
36
|
+
use Orthoses::ActiveSupport::Aliasing
|
23
37
|
use Orthoses::ActiveSupport::ClassAttribute
|
24
38
|
use Orthoses::ActiveSupport::Concern
|
25
39
|
use Orthoses::ActiveSupport::Delegation
|
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-30 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.10'
|
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.10'
|
27
27
|
description: Orthoses middleware collection for Ruby on Rails
|
28
28
|
email:
|
29
29
|
- co000ri@gmail.com
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- LICENSE.txt
|
36
36
|
- README.md
|
37
37
|
- lib/generators/orthoses/rails/install_generator.rb
|
38
|
+
- lib/generators/orthoses/rails/templates/rails.rake
|
38
39
|
- lib/orthoses-rails.rb
|
39
40
|
- lib/orthoses/active_model.rb
|
40
41
|
- lib/orthoses/active_model/has_secure_password.rb
|
@@ -48,7 +49,11 @@ files:
|
|
48
49
|
- lib/orthoses/active_record/query_methods.rb
|
49
50
|
- lib/orthoses/active_record/relation.rb
|
50
51
|
- lib/orthoses/active_record/scope.rb
|
52
|
+
- lib/orthoses/active_record/secure_token.rb
|
53
|
+
- lib/orthoses/active_storage.rb
|
54
|
+
- lib/orthoses/active_storage/attached/model.rb
|
51
55
|
- lib/orthoses/active_support.rb
|
56
|
+
- lib/orthoses/active_support/aliasing.rb
|
52
57
|
- lib/orthoses/active_support/class_attribute.rb
|
53
58
|
- lib/orthoses/active_support/concern.rb
|
54
59
|
- lib/orthoses/active_support/configurable.rb
|