orthoses-rails 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -0
- data/lib/orthoses/active_model/has_secure_password.rb +16 -12
- data/lib/orthoses/active_record/belongs_to.rb +10 -4
- data/lib/orthoses/active_record/generated_attribute_methods.rb +6 -4
- data/lib/orthoses/active_record/has_many.rb +6 -6
- data/lib/orthoses/active_record/has_one.rb +5 -4
- data/lib/orthoses/active_support/class_attribute.rb +7 -5
- data/lib/orthoses/active_support/concern.rb +5 -3
- data/lib/orthoses/active_support/mattr_accessor.rb +6 -7
- data/lib/orthoses/rails/version.rb +1 -1
- data/orthoses-rails.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdff122ed7b5425e10cdf2fa105b8ffb7a583554589f93f8703bb014abbbafd0
|
4
|
+
data.tar.gz: 6d991ce9480237d0f605bbb3935c50f072c6794594b037e459ef3c0dfdcb92c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f1c3be987e9a8096a89918e4c16ef4ad8170c9e77d3e7a074541c98f4255944dde188b74f3d4693764e1f77d7fc600f6e67f9be6309aa2c433cecc746439af3
|
7
|
+
data.tar.gz: 49eaa832bc2a488b0b390df8fa962990898c6e9873f1476e9eae17d94073f9bc2e538be6fba54ebeaca7e33cc4245f0a68fff705f069e009c8284973d14906b8
|
data/README.md
CHANGED
@@ -3,6 +3,45 @@
|
|
3
3
|
[Orthoses](https://github.com/ksss/orthoses) extension for Ruby on Rails.
|
4
4
|
Orthoses::Rails automatically generates RBS for methods added by Rails.
|
5
5
|
|
6
|
+
## Features
|
7
|
+
|
8
|
+
### Orthoses::ActiveModel::HasSecurePassword
|
9
|
+
|
10
|
+
Add signatures that generated form `ActiveModel::SecurePassword::ClassMethods#has_secure_password`.
|
11
|
+
|
12
|
+
### Orthoses::ActiveRecord::BelongsTo
|
13
|
+
|
14
|
+
Add signatures that generated form `ActiveRecord::Associations::ClassMethods#belongs_to`.
|
15
|
+
|
16
|
+
### Orthoses::ActiveRecord::GeneratedAttributeMethods
|
17
|
+
|
18
|
+
Add signatures that generated from DB schema columns.
|
19
|
+
|
20
|
+
### Orthoses::ActiveRecord::HasMany
|
21
|
+
|
22
|
+
Add signatures that generated form `ActiveRecord::Associations::ClassMethods#has_many`.
|
23
|
+
|
24
|
+
### Orthoses::ActiveRecord::HasOne
|
25
|
+
|
26
|
+
Add signatures that generated form `ActiveRecord::Associations::ClassMethods#has_one`.
|
27
|
+
|
28
|
+
### Orthoses::ActiveSupport::ClassAttribute
|
29
|
+
|
30
|
+
Add signatures that generated form `Class#class_attribute`.
|
31
|
+
|
32
|
+
### Orthoses::ActiveSupport::Concern
|
33
|
+
|
34
|
+
Add signature `extend ActiveSupport::Concern` only.
|
35
|
+
|
36
|
+
### Orthoses::ActiveSupport::MattrAccessor
|
37
|
+
|
38
|
+
Add signatures that generated form `Module#mattr_accessor`, `Module#mattr_reader` and `Module#mattr_writer`.
|
39
|
+
|
40
|
+
### Orthoses::ActiveSupport::TimeWithZone
|
41
|
+
|
42
|
+
Add signatures `Time` and `ActiveSupport::TimeWithZone`.
|
43
|
+
Methods and mixin delegated from `Time` are added to `ActiveSupport::TimeWithZone`.
|
44
|
+
|
6
45
|
## Installation
|
7
46
|
|
8
47
|
Install the gem and add to the application's Gemfile by executing:
|
@@ -13,35 +13,39 @@ module Orthoses
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def call
|
16
|
-
target_method = ::
|
16
|
+
target_method = ::ActiveModel::SecurePassword::ClassMethods.instance_method(:has_secure_password)
|
17
17
|
call_tracer = Orthoses::CallTracer.new
|
18
18
|
|
19
|
-
|
19
|
+
store = call_tracer.trace(target_method) do
|
20
20
|
@loader.call
|
21
21
|
end
|
22
22
|
|
23
23
|
call_tracer.result.each do |method, argument|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
next unless method.receiver.kind_of?(Class)
|
25
|
+
base_name = Utils.module_name(method.receiver)
|
26
|
+
next unless base_name
|
27
|
+
|
28
|
+
attribute = argument[:attribute] || :password
|
29
|
+
full_name = if ::ActiveModel::VERSION::MAJOR < 6
|
30
|
+
"ActiveModel::SecurePassword::InstanceMethodsOnActivation"
|
27
31
|
else
|
28
|
-
|
32
|
+
"#{base_name}::ActiveModel_SecurePassword_InstanceMethodsOnActivation_#{attribute}"
|
29
33
|
end
|
30
|
-
|
31
|
-
mod_name = "ActiveModel_SecurePassword_InstanceMethodsOnActivation_#{attribute}"
|
34
|
+
|
32
35
|
lines = []
|
33
36
|
lines << "attr_reader #{attribute}: String?"
|
34
37
|
lines << "def #{attribute}=: (String) -> String"
|
35
38
|
lines << "def #{attribute}_confirmation=: (String) -> String"
|
36
|
-
lines << "def authenticate_#{attribute}: (String) -> (#{
|
39
|
+
lines << "def authenticate_#{attribute}: (String) -> (#{base_name} | false)"
|
37
40
|
if attribute == :password
|
38
41
|
lines << "alias authenticate authenticate_password"
|
39
42
|
end
|
40
|
-
|
41
|
-
|
43
|
+
store[full_name].header = "module #{full_name}"
|
44
|
+
store[full_name].concat(lines)
|
45
|
+
store[base_name] << "include #{full_name}"
|
42
46
|
end
|
43
47
|
|
44
|
-
|
48
|
+
store
|
45
49
|
end
|
46
50
|
end
|
47
51
|
end
|
@@ -11,6 +11,7 @@ module Orthoses
|
|
11
11
|
@loader.call.tap do |store|
|
12
12
|
::ActiveRecord::Base.descendants.each do |base|
|
13
13
|
next if base.abstract_class?
|
14
|
+
base_name = Orthoses::Utils.module_name(base) || next
|
14
15
|
|
15
16
|
lines = base.reflect_on_all_associations(:belongs_to).flat_map do |ref|
|
16
17
|
# FIXME: Can I get list of class for polymorphic?
|
@@ -30,11 +31,16 @@ module Orthoses
|
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
|
-
generated_association_methods = "#{
|
34
|
-
store["module #{generated_association_methods}"].concat(lines)
|
34
|
+
generated_association_methods = "#{base_name}::GeneratedAssociationMethods"
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
store[generated_association_methods].tap do |content|
|
37
|
+
content.header = "module #{generated_association_methods}"
|
38
|
+
content.concat(lines)
|
39
|
+
end
|
40
|
+
|
41
|
+
store[base_name].tap do |content|
|
42
|
+
store[base_name] << "include #{generated_association_methods}"
|
43
|
+
end
|
38
44
|
end
|
39
45
|
end
|
40
46
|
end
|
@@ -12,9 +12,7 @@ module Orthoses
|
|
12
12
|
::ActiveRecord::Base.descendants.each do |klass|
|
13
13
|
next if klass.abstract_class?
|
14
14
|
|
15
|
-
name = klass
|
16
|
-
generated_attribute_methods = "#{name}::AttributeMethods::GeneratedAttributeMethods"
|
17
|
-
store[name] << "include #{generated_attribute_methods}"
|
15
|
+
name = Utils.module_name(klass) || next
|
18
16
|
lines = klass.columns.flat_map do |col|
|
19
17
|
req = sql_type_to_rbs(col.type)
|
20
18
|
opt = "#{req}?"
|
@@ -41,7 +39,11 @@ module Orthoses
|
|
41
39
|
"def clear_#{col.name}_change: () -> void",
|
42
40
|
]
|
43
41
|
end
|
44
|
-
|
42
|
+
generated_attribute_methods = "#{name}::AttributeMethods::GeneratedAttributeMethods"
|
43
|
+
store[name] << "include #{generated_attribute_methods}"
|
44
|
+
|
45
|
+
store[generated_attribute_methods].header = "module #{generated_attribute_methods}"
|
46
|
+
store[generated_attribute_methods].concat(lines)
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
@@ -11,9 +11,9 @@ module Orthoses
|
|
11
11
|
@loader.call.tap do |store|
|
12
12
|
::ActiveRecord::Base.descendants.each do |base|
|
13
13
|
next if base.abstract_class?
|
14
|
+
base_name = Utils.module_name(base) || next
|
14
15
|
|
15
|
-
|
16
|
-
collection_proxy = "#{base}::ActiveRecord_Associations_CollectionProxy"
|
16
|
+
collection_proxy = "#{base_name}::ActiveRecord_Associations_CollectionProxy"
|
17
17
|
|
18
18
|
lines = base.reflect_on_all_associations(:has_many).flat_map do |ref|
|
19
19
|
singular_name = ref.name.to_s.singularize
|
@@ -26,10 +26,10 @@ module Orthoses
|
|
26
26
|
]
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
store[
|
29
|
+
generated_association_methods = "#{base_name}::GeneratedAssociationMethods"
|
30
|
+
store[generated_association_methods].header = "module #{generated_association_methods}"
|
31
|
+
store[generated_association_methods].concat(lines)
|
32
|
+
store[base_name] << "include #{generated_association_methods}"
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -11,6 +11,7 @@ module Orthoses
|
|
11
11
|
@loader.call.tap do |store|
|
12
12
|
::ActiveRecord::Base.descendants.each do |base|
|
13
13
|
next if base.abstract_class?
|
14
|
+
base_name = Utils.module_name(base) || next
|
14
15
|
|
15
16
|
lines = base.reflect_on_all_associations(:has_one).flat_map do |ref|
|
16
17
|
type = ref.klass.to_s
|
@@ -26,11 +27,11 @@ module Orthoses
|
|
26
27
|
]
|
27
28
|
end
|
28
29
|
|
29
|
-
generated_association_methods = "#{
|
30
|
-
store["module #{generated_association_methods}"
|
30
|
+
generated_association_methods = "#{base_name}::GeneratedAssociationMethods"
|
31
|
+
store[generated_association_methods].header = "module #{generated_association_methods}"
|
32
|
+
store[generated_association_methods].concat(lines)
|
31
33
|
|
32
|
-
|
33
|
-
store[base.to_s] << code
|
34
|
+
store[base_name] << "include #{generated_association_methods}"
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
@@ -15,17 +15,19 @@ module Orthoses
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def call
|
18
|
-
require 'active_support/core_ext/class/attribute'
|
19
18
|
target_method = ::Class.instance_method(:class_attribute)
|
20
19
|
call_tracer = Orthoses::CallTracer.new
|
21
20
|
|
22
|
-
|
21
|
+
store = call_tracer.trace(target_method) do
|
23
22
|
@loader.call
|
24
23
|
end
|
25
24
|
|
26
25
|
call_tracer.result.each do |method, argument|
|
26
|
+
receiver_name = Orthoses::Utils.module_name(method.receiver)
|
27
|
+
next unless receiver_name
|
28
|
+
|
27
29
|
methods = []
|
28
|
-
if ::ActiveSupport
|
30
|
+
if ::ActiveSupport::VERSION::MAJOR < 6
|
29
31
|
options = argument[:attrs].extract_options!
|
30
32
|
argument[:instance_reader] = options.fetch(:instance_accessor, true) && options.fetch(:instance_reader, true)
|
31
33
|
argument[:instance_writer] = options.fetch(:instance_accessor, true) && options.fetch(:instance_writer, true)
|
@@ -49,10 +51,10 @@ module Orthoses
|
|
49
51
|
end
|
50
52
|
next if methods.empty?
|
51
53
|
|
52
|
-
|
54
|
+
store[receiver_name].concat(methods)
|
53
55
|
end
|
54
56
|
|
55
|
-
|
57
|
+
store
|
56
58
|
end
|
57
59
|
end
|
58
60
|
end
|
@@ -9,13 +9,15 @@ module Orthoses
|
|
9
9
|
|
10
10
|
def call
|
11
11
|
extended = CallTracer.new
|
12
|
-
|
12
|
+
store = extended.trace(::ActiveSupport::Concern.method(:extended)) do
|
13
13
|
@loader.call
|
14
14
|
end
|
15
15
|
extended.result.each do |method, argument|
|
16
|
-
|
16
|
+
base_name = Orthoses::Utils.module_name(argument[:base])
|
17
|
+
next unless base_name
|
18
|
+
store[argument[:base].to_s] << "extend ActiveSupport::Concern"
|
17
19
|
end
|
18
|
-
|
20
|
+
store
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
@@ -16,15 +16,14 @@ module Orthoses
|
|
16
16
|
mattr_reader = Orthoses::CallTracer.new
|
17
17
|
mattr_writer = Orthoses::CallTracer.new
|
18
18
|
|
19
|
-
|
20
|
-
result = mattr_reader.trace(::Module.instance_method(:mattr_reader)) do
|
19
|
+
store = mattr_reader.trace(::Module.instance_method(:mattr_reader)) do
|
21
20
|
mattr_writer.trace(::Module.instance_method(:mattr_writer)) do
|
22
21
|
@loader.call
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
25
|
mattr_reader.result.each do |method, argument|
|
27
|
-
base = method.receiver
|
26
|
+
base = Orthoses::Utils.module_name(method.receiver) || next
|
28
27
|
methods = []
|
29
28
|
argument[:syms].each do |sym|
|
30
29
|
next unless @if.nil? || @if.call(method, sym)
|
@@ -36,11 +35,11 @@ module Orthoses
|
|
36
35
|
end
|
37
36
|
next if methods.empty?
|
38
37
|
|
39
|
-
|
38
|
+
store[base].concat(methods)
|
40
39
|
end
|
41
40
|
|
42
41
|
mattr_writer.result.each do |method, argument|
|
43
|
-
base = method.receiver
|
42
|
+
base = Orthoses::Utils.module_name(method.receiver) || next
|
44
43
|
methods = []
|
45
44
|
argument[:syms].each do |sym|
|
46
45
|
next unless @if.nil? || @if.call(method, sym)
|
@@ -52,10 +51,10 @@ module Orthoses
|
|
52
51
|
end
|
53
52
|
next if methods.empty?
|
54
53
|
|
55
|
-
|
54
|
+
store[base].concat(methods)
|
56
55
|
end
|
57
56
|
|
58
|
-
|
57
|
+
store
|
59
58
|
end
|
60
59
|
end
|
61
60
|
end
|
data/orthoses-rails.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["ksss"]
|
9
9
|
spec.email = ["co000ri@gmail.com"]
|
10
10
|
|
11
|
-
spec.summary = "Orthoses
|
11
|
+
spec.summary = "Orthoses middleware collection for Ruby on Rails"
|
12
12
|
spec.description = "Orthoses middleware collection for Ruby on Rails"
|
13
13
|
spec.homepage = "https://github.com/ksss/orthoses-rails"
|
14
14
|
spec.license = "MIT"
|
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: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: orthoses
|
@@ -72,8 +72,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '0'
|
74
74
|
requirements: []
|
75
|
-
rubygems_version: 3.
|
75
|
+
rubygems_version: 3.3.7
|
76
76
|
signing_key:
|
77
77
|
specification_version: 4
|
78
|
-
summary: Orthoses
|
78
|
+
summary: Orthoses middleware collection for Ruby on Rails
|
79
79
|
test_files: []
|