Class: Orthoses::RBSPrototypeRB

Inherits:
Object
  • Object
show all
Defined in:
lib/orthoses/rbs_prototype_rb.rb

Overview

Call ‘rbs prototype rb` and add to store

use Orthoses::RBSPrototypeRB,
  paths: Dir.glob("lib/**/*.rb"),
  method_definition_filter: ->(member) { false },
  alias_filter: ->(member) { false }

Instance Method Summary collapse

Constructor Details

#initialize(loader, paths:, method_definition_filter: nil, alias_filter: nil, constant_filter: nil, mixin_filter: nil, attribute_filter: nil) ⇒ RBSPrototypeRB

Returns a new instance of RBSPrototypeRB.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/orthoses/rbs_prototype_rb.rb', line 8

def initialize(
  loader,
  paths:,
  method_definition_filter: nil,
  alias_filter: nil,
  constant_filter: nil,
  mixin_filter: nil,
  attribute_filter: nil
)
  @loader = loader
  @paths = paths
  @method_definition_filter = method_definition_filter
  @alias_filter = alias_filter
  @constant_filter = constant_filter
  @mixin_filter = mixin_filter
  @attribute_filter = attribute_filter
end

Instance Method Details

#callObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/orthoses/rbs_prototype_rb.rb', line 26

def call
  @loader.call.tap do |store|
    parser = RBS::Prototype::RB.new
    @paths.each do |path|
      begin
        Orthoses.logger.debug("parse #{path} by RBS::Prototype::RB")
        parser.parse File.read(path.to_s)
      rescue => err
        Orthoses.logger.error("Parse error #{err.inspect} by RBS::Prototype::RB #{path}")
      end
    end
    env = Orthoses::Content::Environment.new(
      method_definition_filter: @method_definition_filter,
      alias_filter: @alias_filter,
      constant_filter: @constant_filter,
      mixin_filter: @mixin_filter,
      attribute_filter: @attribute_filter,
    )
    parser.decls.each do |decl|
      env << decl
    end
    env.write_to(store: store)
  end
end