orthoses-rails 0.7.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 721183c8c3c14666265aa24ecfe51ba9703afe1ed99bf5e320b6c57c2e995722
4
- data.tar.gz: deabd621c4483c341b687dc5562c72aa52a49c4b983544244dc9e2b736cd056d
3
+ metadata.gz: a43ce53af9e7aec6ef02751c5649146d817e76770a9b15bb2fb5a24fa1b0447b
4
+ data.tar.gz: 83c78756ff7794059a1001902f887509d8be7b42f116a2ce30b1cdb27d75ff6a
5
5
  SHA512:
6
- metadata.gz: ed8956fbfd018c4dbd650c1c20c9d46172c1cabafd286de074dbcda62d5f898125d66b12a4b461097eb6134dd3dd9dac9546157a794152064201d12261bc3365
7
- data.tar.gz: c4154bd4a83864ebf2f8a13fa7cffd4bb721374f9d05674a234565efc3676ac0a837aef866233ef9f256351b70022cc60bd07f199f588d57e6bba50f0edca819
6
+ metadata.gz: bce1abdf1faf93222005ba51aa4c74675fc98edef98a546faecd52280bf03ce11dc896379ab7269c3c7bda3be43eddae81cf01ab6fc701e8a2e96d4f841dd7b8
7
+ data.tar.gz: be065396c52d757e110c2668e5eb90ada5f58275376bc93f0e9e4d25be4968735bccae5ace6d2ad7e08c8642b75b1ff5f5bd63b93c4019faba66101f1de34757
data/README.md CHANGED
@@ -48,34 +48,35 @@ If bundler is not being used to manage dependencies, install the gem by executin
48
48
 
49
49
  ## Usage
50
50
 
51
+ Build your Rake task for RBS generation.
52
+
51
53
  ```rb
52
- Orthoses::Builder.new do
53
- use Orthoses::CreateFileByName
54
- base_dir: Rails.root.join("sig/out"),
55
- header: "# !!! GENERATED CODE !!!"
56
- use Orthoses::Filter,
57
- if: -> (name, _content) {
54
+ task :rbs_generate => :environment do
55
+ Orthoses::Builder.new do
56
+ use Orthoses::CreateFileByName
57
+ base_dir: Rails.root.join("sig/out"),
58
+ header: "# !!! GENERATED CODE !!!"
59
+ use Orthoses::Filter do |name, _content|
58
60
  path, _lineno = Object.const_source_location(name)
59
61
  return false unless path
60
62
  %r{app/models}.match?(path)
63
+ end
64
+ use YourCustom::Middleware
65
+ use Orthoses::ActiveModel::HasSecurePassword
66
+ use Orthoses::ActiveRecord::BelongsTo
67
+ use Orthoses::ActiveRecord::HasMany
68
+ use Orthoses::ActiveRecord::HasOne
69
+ use Orthoses::ActiveSupport::ClassAttribute
70
+ use Orthoses::ActiveSupport::MattrAccessor
71
+ use Orthoses::Mixin
72
+ use Orthoses::Constant, strict: false
73
+ use Orthoses::ObjectSpaceAll
74
+ use Orthoses::Autoload
75
+ run -> {
76
+ Rails.application.eager_load!
61
77
  }
62
- use YourCustom::Middleware
63
- use Orthoses::ActiveModel::HasSecurePassword
64
- use Orthoses::ActiveRecord::BelongsTo
65
- use Orthoses::ActiveRecord::HasMany
66
- use Orthoses::ActiveRecord::HasOne
67
- use Orthoses::ActiveSupport::ClassAttribute
68
- use Orthoses::ActiveSupport::MattrAccessor
69
- use Orthoses::Mixin
70
- use Orthoses::Constant, strict: false
71
- use Orthoses::ObjectSpaceAll
72
- use Orthoses::Autoload
73
- run -> () {
74
- Rake::Task[:environment].invoke
75
- Rails.application.eager_load!
76
- Orthoses::Utils.unautoload!
77
- }
78
- end.call
78
+ end.call
79
+ end
79
80
  ```
80
81
 
81
82
  ## Development
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- orthoses-rails (0.6.0)
5
- orthoses (>= 0.10)
4
+ orthoses-rails (0.7.0)
5
+ orthoses (~> 1.0)
6
6
 
7
7
  PATH
8
8
  remote: _src
@@ -134,9 +134,9 @@ GEM
134
134
  nokogiri (1.13.8)
135
135
  mini_portile2 (~> 2.8.0)
136
136
  racc (~> 1.4)
137
- orthoses (0.11.0)
137
+ orthoses (1.0.0)
138
138
  rbs (~> 2.0)
139
- psych (3.3.2)
139
+ psych (3.3.3)
140
140
  racc (1.6.0)
141
141
  rack (2.2.4)
142
142
  rack-test (2.0.2)
@@ -148,7 +148,8 @@ GEM
148
148
  loofah (~> 2.3)
149
149
  rake (13.0.6)
150
150
  rbs (2.6.0)
151
- sqlite3 (1.4.4)
151
+ sqlite3 (1.5.0)
152
+ mini_portile2 (~> 2.8.0)
152
153
  strscan (3.0.4)
153
154
  thor (1.2.1)
154
155
  timeout (0.3.0)
@@ -67,22 +67,21 @@ def generate(out_dir, version)
67
67
  use Orthoses::CreateFileByName,
68
68
  base_dir: "#{out_dir}/#{version}",
69
69
  header: "# !!! GENERATED CODE !!!\n# Please see generators/rails-generator"
70
- use Orthoses::Filter,
71
- if: -> (name, content) {
72
- # OMG, both ERB and Erb are exist...
73
- return false if name.start_with?("Erb")
70
+ use Orthoses::Filter do |name, content|
71
+ # OMG, both ERB and Erb are exist...
72
+ return false if name.start_with?("Erb")
74
73
 
75
- # ArgumentError
76
- return false if name.start_with?("I18n::Tests")
74
+ # ArgumentError
75
+ return false if name.start_with?("I18n::Tests")
77
76
 
78
- # FIXME: too hard
79
- return false if name.include?("::Generators")
77
+ # FIXME: too hard
78
+ return false if name.include?("::Generators")
80
79
 
81
- # Ignore known sig
82
- return false if Orthoses::Utils.rbs_defined_class?(name, collection: true) && content.body.empty?
80
+ # Ignore known sig
81
+ return false if Orthoses::Utils.rbs_defined_class?(name, collection: true) && content.body.empty?
83
82
 
84
- true
85
- }
83
+ true
84
+ end
86
85
  use Orthoses::Constant,
87
86
  strict: false,
88
87
  if: -> (current, const, _val, _rbs) {
@@ -1,21 +1,4 @@
1
- module DateAndTime
2
- module Calculations
3
- end
4
- module Zones
5
- end
6
- module Compatibility
7
- end
8
- end
9
- module ActiveSupport
10
- class TimeZone
11
- end
12
- class Duration
13
- end
14
- end
15
-
16
1
  class Time
17
- include DateAndTime::Calculations
18
-
19
2
  # Returns <tt>Time.zone.now</tt> when <tt>Time.zone</tt> or <tt>config.time_zone</tt> are set, otherwise just returns <tt>Time.now</tt>.
20
3
  def self.current: () -> ActiveSupport::TimeWithZone # strictly `(ActiveSupport::TimeWithZone | Time)` but it's inconvenient
21
4
  def self.zone: () -> ActiveSupport::TimeZone # strictly `ActiveSupport::TimeWithZone?` but it's inconvenient
@@ -29,16 +12,6 @@ class Time
29
12
  | ...
30
13
  def -: (ActiveSupport::Duration other) -> self
31
14
  | ...
32
- alias at_beginning_of_day beginning_of_day
33
- alias at_beginning_of_hour beginning_of_hour
34
- alias at_beginning_of_minute beginning_of_minute
35
- alias at_end_of_day end_of_day
36
- alias at_end_of_hour end_of_hour
37
- alias at_end_of_minute end_of_minute
38
- alias at_midday middle_of_day
39
- alias at_middle_of_day middle_of_day
40
- alias at_midnight beginning_of_day
41
- alias at_noon middle_of_day
42
15
  def beginning_of_day: () -> self
43
16
  def beginning_of_hour: () -> self
44
17
  def beginning_of_minute: () -> self
@@ -49,9 +22,7 @@ class Time
49
22
  def end_of_minute: () -> self
50
23
  def eql_with_coercion: (untyped other) -> bool
51
24
  def eql_without_coercion: (untyped other) -> bool
52
- alias midday middle_of_day
53
25
  def middle_of_day: () -> self
54
- alias midnight beginning_of_day
55
26
  def minus_with_coercion: (Time | self arg0) -> Float
56
27
  | (Numeric arg0) -> self
57
28
  def minus_with_duration: (Time | self arg0) -> Float
@@ -63,7 +34,6 @@ class Time
63
34
  def next_day: () -> self
64
35
  def next_month: () -> self
65
36
  def next_year: () -> self
66
- alias noon middle_of_day
67
37
  def plus_without_duration: (Time | self arg0) -> Float
68
38
  | (Numeric arg0) -> self
69
39
  def prev_day: () -> self
@@ -12,10 +12,7 @@ VERSIONS.each do |version|
12
12
  sh "rm -fr #{export}"
13
13
  sh "mkdir -p #{export}"
14
14
 
15
- if File.exist?("out/#{version}/active_record/destroy_association_async_job.rbs")
16
- sh "mkdir -p #{export}/active_record"
17
- sh "cp out/#{version}/active_record/destroy_association_async_job.rbs #{export}/active_record/destroy_association_async_job.rbs"
18
- end
15
+ sh "cp -a out/#{version}/railties_mixin #{export}"
19
16
  end
20
17
 
21
18
  desc "validate version=#{version} gem=railties"
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Orthoses
4
+ module ActiveSupport
5
+ class Concern
6
+ def initialize(loader)
7
+ @loader = loader
8
+ end
9
+
10
+ def call
11
+ lazy_tracer = Orthoses::CallTracer::Lazy.new
12
+
13
+ store = lazy_tracer.trace('ActiveSupport::Concern#class_methods') do
14
+ @loader.call
15
+ end
16
+
17
+ lazy_tracer.captures.each do |capture|
18
+ receiver_name = Orthoses::Utils.module_name(capture.method.receiver)
19
+ next unless receiver_name
20
+
21
+ class_methods_name = "#{receiver_name}::ClassMethods"
22
+ members = members_prototype_of(class_methods_name)
23
+
24
+ writer = ::RBS::Writer.new(out: StringIO.new)
25
+ members.each do |member|
26
+ writer.write_member(member)
27
+ end
28
+ out = writer.out
29
+ # NOTE: Should I remove the method that is accidentally added in prototype rb?
30
+ store[class_methods_name].concat(out.string.each_line.to_a)
31
+ end
32
+
33
+ store
34
+ end
35
+
36
+ def members_prototype_of(mod_name)
37
+ mod = Object.const_get(mod_name)
38
+ runtime = ::RBS::Prototype::Runtime.new(patterns: nil, env: nil, merge: false)
39
+ type_name = runtime.to_type_name(mod_name)
40
+ [].tap do |members|
41
+ runtime.generate_methods(mod, type_name, members)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -117,11 +117,11 @@ module Orthoses
117
117
  if argument
118
118
  return [:multi, member.types]
119
119
  else
120
- type = member.types.find do |method_type|
120
+ method_type = member.overloads.map(&:method_type).find do |method_type|
121
121
  method_type.type.required_positionals.empty? && method_type.type.required_keywords.empty?
122
122
  end
123
- next unless type
124
- return [:single, type.type.return_type]
123
+ next unless method_type
124
+ return [:single, method_type.type.return_type]
125
125
  end
126
126
  when RBS::AST::Members::Var
127
127
  next unless member.name == name
@@ -35,19 +35,25 @@ module Orthoses
35
35
  -
36
36
  ])
37
37
 
38
+ def add_signature(env, content)
39
+ buffer, directives, decls = RBS::Parser.parse_signature(content.to_rbs)
40
+ env.add_signature(buffer: buffer, directives: directives, decls: decls)
41
+ end
42
+
38
43
  def each_line_from_core_time_definition(store)
39
44
  type_name_time = TypeName("::Time")
40
45
  type_name_time_with_zone = TypeName("::ActiveSupport::TimeWithZone")
41
46
  env = Utils.rbs_environment(collection: true, cache: false)
42
- env << store["Time"].to_decl
43
- env << store["DateAndTime"].to_decl
44
- env << store["DateAndTime::Zones"].to_decl
45
- env << store["DateAndTime::Calculations"].to_decl
46
- env << store["DateAndTime::Compatibility"].to_decl
47
- env << store["ActiveSupport"].to_decl
48
- env << store["ActiveSupport::TimeZone"].to_decl
49
- env << store["ActiveSupport::Duration"].to_decl
50
- env << store["ActiveSupport::TimeWithZone"].to_decl
47
+
48
+ add_signature(env, store["Time"])
49
+ add_signature(env, store["DateAndTime"])
50
+ add_signature(env, store["DateAndTime::Zones"])
51
+ add_signature(env, store["DateAndTime::Calculations"])
52
+ add_signature(env, store["DateAndTime::Compatibility"])
53
+ add_signature(env, store["ActiveSupport"])
54
+ add_signature(env, store["ActiveSupport::TimeZone"])
55
+ add_signature(env, store["ActiveSupport::Duration"])
56
+ add_signature(env, store["ActiveSupport::TimeWithZone"])
51
57
 
52
58
  builder = RBS::DefinitionBuilder.new(env: env.resolve_type_names)
53
59
  one_ancestors = builder.ancestor_builder.one_instance_ancestors(type_name_time)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'active_support/class_attribute'
4
+ require_relative 'active_support/concern'
4
5
  require_relative 'active_support/configurable'
5
6
  require_relative 'active_support/delegation'
6
7
  require_relative 'active_support/mattr_accessor'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Orthoses
4
4
  module Rails
5
- VERSION = "0.7.0"
5
+ VERSION = "0.9.0"
6
6
  end
7
7
  end
@@ -32,5 +32,5 @@ Gem::Specification.new do |spec|
32
32
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
33
  spec.require_paths = ["lib"]
34
34
 
35
- spec.add_dependency "orthoses", ">= 0.11"
35
+ spec.add_dependency "orthoses", ">= 1.6"
36
36
  end
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.7.0
4
+ version: 0.9.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-08-28 00:00:00.000000000 Z
11
+ date: 2023-04-02 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: '0.11'
19
+ version: '1.6'
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: '0.11'
26
+ version: '1.6'
27
27
  description: Orthoses middleware collection for Ruby on Rails
28
28
  email:
29
29
  - co000ri@gmail.com
@@ -87,6 +87,7 @@ files:
87
87
  - lib/orthoses/active_record/scope.rb
88
88
  - lib/orthoses/active_support.rb
89
89
  - lib/orthoses/active_support/class_attribute.rb
90
+ - lib/orthoses/active_support/concern.rb
90
91
  - lib/orthoses/active_support/configurable.rb
91
92
  - lib/orthoses/active_support/delegation.rb
92
93
  - lib/orthoses/active_support/mattr_accessor.rb
@@ -119,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
120
  - !ruby/object:Gem::Version
120
121
  version: '0'
121
122
  requirements: []
122
- rubygems_version: 3.4.0.dev
123
+ rubygems_version: 3.4.6
123
124
  signing_key:
124
125
  specification_version: 4
125
126
  summary: Orthoses middleware collection for Ruby on Rails