orthoses-rails 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76d6291b36d7d10e10f2d5b0898fa06a8a886375f9f91e91b2db718847c42eb2
4
- data.tar.gz: 9d33694af285fdc0a214af35c26e143990689bca720429ca7029ccb48f0e531b
3
+ metadata.gz: fdff122ed7b5425e10cdf2fa105b8ffb7a583554589f93f8703bb014abbbafd0
4
+ data.tar.gz: 6d991ce9480237d0f605bbb3935c50f072c6794594b037e459ef3c0dfdcb92c3
5
5
  SHA512:
6
- metadata.gz: a00f874e057a7515e2427bef047c25fc4a5bfe5f698e177b4e3919b4acc2df4cd4093b8fd407c7c493a1b548bbed0340f916af6f43bb37b0bd01e128f3ca3f8f
7
- data.tar.gz: 77d8183eafa99f69864d37eae0dea091f0a2d0cf57530d10d524c61cb2ababdd8478ba6a2aad19e3be76119af7a6ee7be8e7fcd3bb8d1a7c06487c54aef3ebf3
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 = ::ActiveRecord::Base.method(:has_secure_password)
16
+ target_method = ::ActiveModel::SecurePassword::ClassMethods.instance_method(:has_secure_password)
17
17
  call_tracer = Orthoses::CallTracer.new
18
18
 
19
- result = call_tracer.trace(target_method) do
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
- base = method.receiver.to_s
25
- if argument[:attribute].nil? # < 6.0
26
- result[base].delete_if { |line| line == "include ActiveModel::SecurePassword::InstanceMethodsOnActivation" }
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
- result[base].delete_if { |line| line.start_with?("include #<InstanceMethodsOnActivation:") }
32
+ "#{base_name}::ActiveModel_SecurePassword_InstanceMethodsOnActivation_#{attribute}"
29
33
  end
30
- attribute = argument[:attribute] || :password
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) -> (#{base} | false)"
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
- result["module #{base}::#{mod_name}"].concat(lines)
41
- result[base] << "include #{mod_name}"
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
- result
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 = "#{base}::GeneratedAssociationMethods"
34
- store["module #{generated_association_methods}"].concat(lines)
34
+ generated_association_methods = "#{base_name}::GeneratedAssociationMethods"
35
35
 
36
- code = "include #{generated_association_methods}"
37
- store[base.to_s] << code
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.to_s
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
- store["module #{generated_attribute_methods}"].concat(lines)
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
- generated_association_methods = "#{base}::GeneratedAssociationMethods"
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
- store["module #{generated_association_methods}"].concat(lines)
30
-
31
- code = "include #{generated_association_methods}"
32
- store[base.to_s] << code
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 = "#{base}::GeneratedAssociationMethods"
30
- store["module #{generated_association_methods}"].concat(lines)
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
- code = "include #{generated_association_methods}"
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
- result = call_tracer.trace(target_method) do
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.version < Gem::Version.new("6.0")
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
- result[method.receiver.to_s].concat(methods)
54
+ store[receiver_name].concat(methods)
53
55
  end
54
56
 
55
- result
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
- result = extended.trace(::ActiveSupport::Concern.method(:extended)) do
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
- result[argument[:base].to_s] << "extend ActiveSupport::Concern"
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
- result
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
- require 'active_support/core_ext/module/attribute_accessors.rb'
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.to_s
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
- result[base].concat(methods)
38
+ store[base].concat(methods)
40
39
  end
41
40
 
42
41
  mattr_writer.result.each do |method, argument|
43
- base = method.receiver.to_s
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
- result[base].concat(methods)
54
+ store[base].concat(methods)
56
55
  end
57
56
 
58
- result
57
+ store
59
58
  end
60
59
  end
61
60
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Orthoses
4
4
  module Rails
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
@@ -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 middleware collection for Ruby on Rails"
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.1.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-09 00:00:00.000000000 Z
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.4.0.dev
75
+ rubygems_version: 3.3.7
76
76
  signing_key:
77
77
  specification_version: 4
78
- summary: Orthoses middleware collection for Ruby on Rails
78
+ summary: Orthoses middleware collection for Ruby on Rails
79
79
  test_files: []