orthoses 0.11.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1bbebf8271fbe9859e0e322e0e2d12fbf7a03dc30663309771edeba678674679
4
- data.tar.gz: bfdfabbb3110a7c159a7763463077768d76b9cfd14ae77537a87d0abbd8fda74
3
+ metadata.gz: 8718c01d3ca0c5ea18285c9082218c526e280626d15da555b17773ec8d582ac3
4
+ data.tar.gz: 2541364526894cb9f2870a4a69169418ca57ad042911507bd96557e54df1abfd
5
5
  SHA512:
6
- metadata.gz: e1093d5bbc23bf0577d915afd70fa34907316bcdd2062e34cdc7506f455636e47e02bb046048e4682c16feeba2bc045985fbae2636bd2e220fc90a66f30e957b
7
- data.tar.gz: 84fe1da94bfe208b46ddc1b3607ba7962e1133150fe454ffc8d4e40ca0dd6bc99c4b7e24f41a18f0217913eedd6e5b08e45329d07455e1e5fb913d102c13b67e
6
+ metadata.gz: b8dbc5aaeda5a1943a61bfc8b0190994373284e5c4712d2ffe710fe31fe95949406b8d2a3929dfad09b573b14c19d81c7f558cbc7ac197055d128596e2625272
7
+ data.tar.gz: 465cff7f5fa29e7b599549a790b85ba1d597e820e6437811ead5e8de031fee797ef07746bba448451b2b73715511e8bd59a65cb8b32bf86ab1d09832a06ac3a7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- orthoses (0.11.0)
4
+ orthoses (1.1.0)
5
5
  rbs (~> 2.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -3,6 +3,10 @@
3
3
  Orthoses is a framework for RBS generation.
4
4
  The Rack architecture keeps your code organized and extensible.
5
5
 
6
+ - You can choose which middleware to use.
7
+ - You can write your own middleware to use.
8
+ - You can publish your middleware and share it with the world.
9
+
6
10
  ## PoC
7
11
 
8
12
  https://gist.github.com/ksss/00592da24f28774bf8fc5db08331666e
@@ -19,28 +23,38 @@ If bundler is not being used to manage dependencies, install the gem by executin
19
23
 
20
24
  ## Usage
21
25
 
26
+ For example, You can write script in Rakefile.
27
+
22
28
  ```rb
23
- Orthoses::Builder.new do
24
- use Orthoses::CreateFileByName
25
- base_dir: Rails.root.join("sig/out"),
26
- header: "# !!! GENERATED CODE !!!"
27
- use Orthoses::Filter,
28
- if: -> (name, _content) {
29
- path, _lineno = Object.const_source_location(name)
30
- return false unless path
31
- %r{app/models}.match?(path)
32
- }
33
- use YourCustom::Middleware
34
- use Orthoses::Mixin
35
- use Orthoses::Constant
36
- use Orthoses::Walk,
37
- root: "Foo"
38
- run -> () {
39
- # load library or application
40
- }
41
- end.call
29
+ require 'orthoses'
30
+
31
+ namespace :rbs do
32
+ desc "build RBS to sig/out"
33
+ task :build do
34
+ Orthoses::Builder.new do
35
+ use Orthoses::CreateFileByName
36
+ base_dir: Rails.root.join("sig/out"),
37
+ header: "# !!! GENERATED CODE !!!"
38
+ use Orthoses::Filter do |name, _content|
39
+ path, _lineno = Object.const_source_location(name)
40
+ return false unless path
41
+ %r{app/models}.match?(path)
42
+ end
43
+ use YourCustom::Middleware
44
+ use Orthoses::Mixin
45
+ use Orthoses::Constant
46
+ use Orthoses::Walk,
47
+ root: "Foo"
48
+ run -> {
49
+ # load library or application
50
+ }
51
+ end.call
52
+ end
53
+ end
42
54
  ```
43
55
 
56
+ Then, you can see the result files under `sig/out`.
57
+
44
58
  ## Utils
45
59
 
46
60
  `Orthoses::Utils` is a collection of useful methods.
@@ -177,3 +191,9 @@ The gem is available as open source under the terms of the [MIT License](https:/
177
191
  ## Code of Conduct
178
192
 
179
193
  Everyone interacting in the Orthoses project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ksss/orthoses/blob/main/CODE_OF_CONDUCT.md).
194
+
195
+ # TODO
196
+
197
+ - Share middleware sets for commonly used use cases.
198
+ - For library.
199
+ - For application.
@@ -13,9 +13,9 @@ task :minitest => :src do
13
13
  Orthoses::Builder.new do
14
14
  use Orthoses::CreateFileByName,
15
15
  base_dir: out.to_s
16
- use Orthoses::Filter, if: ->(name, content) {
16
+ use Orthoses::Filter do |name, content|
17
17
  name.start_with?("Minitest") || name == "Kernel"
18
- }
18
+ end
19
19
  use Orthoses::Constant,
20
20
  strict: false,
21
21
  if: ->(current, const, val, rbs){
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Orthoses
4
4
  class Constant
5
- def initialize(loader, strict:, if: nil, on_error: nil)
5
+ def initialize(loader, strict: false, if: nil, on_error: nil)
6
6
  @loader = loader
7
7
  @strict = strict
8
8
  @if = binding.local_variable_get(:if)
@@ -11,11 +11,16 @@ module Orthoses
11
11
  return unless @decl.respond_to?(:members)
12
12
  uniq_map = {}
13
13
  @decl.members.each do |member|
14
- key = member_key(member)
15
- drop_member = uniq_map[key]
16
- uniq_map[key] = member
17
- if drop_member
18
- Orthoses.logger.info("#{@decl.name} \"#{member.location.source}\" was droped since duplication")
14
+ if member.instance_of?(RBS::AST::Members::MethodDefinition) && member.overload
15
+ # avoid to duplicate and keep order
16
+ uniq_map[Object.new] = member
17
+ else
18
+ key = member_key(member)
19
+ drop_member = uniq_map[key]
20
+ uniq_map[key] = member
21
+ if drop_member
22
+ Orthoses.logger.info("#{@decl.name} \"#{member.location.source}\" was droped since duplication")
23
+ end
19
24
  end
20
25
  end
21
26
  drop_known_method_definition(uniq_map)
@@ -2,19 +2,21 @@
2
2
 
3
3
  module Orthoses
4
4
  # Filter current store.
5
- # use Orthoses::Filter,
6
- # # filter stored key and value if proc return true
7
- # if: -> (name, content) { Orthoses.rbs_defined_class?(name) }
5
+ # filter stored key and value if proc return true
6
+ # use Orthoses::Filter do |name, content|
7
+ # Orthoses.rbs_defined_class?(name)
8
+ # end
8
9
  class Filter
9
- def initialize(loader, if:)
10
+ def initialize(loader, if: nil, &block)
10
11
  @loader = loader
11
12
  @if = binding.local_variable_get(:if)
13
+ @block = block || @if || raise(ArgumentError, "should give a block")
12
14
  end
13
15
 
14
16
  def call
15
17
  @loader.call.tap do |store|
16
18
  store.filter! do |name, content|
17
- @if.call(name, content).tap do
19
+ @block.call(name, content).tap do
18
20
  Orthoses.logger.debug("Filter pass [#{name}]")
19
21
  end
20
22
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Orthoses
4
- VERSION = "0.11.0"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -1,7 +1,7 @@
1
1
  # THIS IS GENERATED CODE from `$ rake generate_self_sig`
2
2
 
3
3
  class Orthoses::Constant
4
- def initialize: (Orthoses::_Call loader, strict: bool, ?if: ^(Module, Symbol, untyped) -> boolish, ?on_error: ^(Orthoses::ConstLoadError) -> void) -> void
4
+ def initialize: (Orthoses::_Call loader, ?strict: bool, ?if: ^(Module, Symbol, untyped) -> boolish | nil, ?on_error: ^(Orthoses::ConstLoadError) -> void | nil) -> void
5
5
  def call: () -> Orthoses::store
6
6
  @loader: Orthoses::_Call
7
7
  @strict: bool
@@ -1,7 +1,8 @@
1
1
  # THIS IS GENERATED CODE from `$ rake generate_self_sig`
2
2
 
3
3
  class Orthoses::Filter
4
- def initialize: (Orthoses::_Call loader, if: ^(String, Orthoses::Content) -> boolish) -> void
4
+ def initialize: (Orthoses::_Call loader) { (String, Orthoses::Content) -> boolish } -> void
5
5
  def call: () -> Orthoses::store
6
6
  @loader: Orthoses::_Call
7
+ @block: ^(String, Orthoses::Content) -> boolish
7
8
  end
data/sig/orthoses.rbs CHANGED
@@ -1,7 +1,7 @@
1
1
  # THIS IS GENERATED CODE from `$ rake generate_self_sig`
2
2
 
3
3
  module Orthoses
4
- VERSION: "0.11.0"
4
+ VERSION: "1.1.0"
5
5
  attr_accessor self.logger: ::Logger
6
6
  type store = Hash[String, Orthoses::Content]
7
7
  INSTANCE_METHOD_METHOD: UnboundMethod
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orthoses
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
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: 2022-08-27 00:00:00.000000000 Z
11
+ date: 2022-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbs