Class: Orthoses::RBSPrototypeRuntime

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

Overview

Call ‘rbs prototype runtime` and add to store

use Orthoses::RBSPrototypeRuntime,
  patterns: ['Foo::*']

Instance Method Summary collapse

Constructor Details

#initialize(loader, patterns: nil, method_definition_filter: nil, alias_filter: nil, constant_filter: nil, mixin_filter: nil, attribute_filter: nil) ⇒ RBSPrototypeRuntime

Returns a new instance of RBSPrototypeRuntime.



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

def initialize(
  loader,
  patterns: nil,
  method_definition_filter: nil,
  alias_filter: nil,
  constant_filter: nil,
  mixin_filter: nil,
  attribute_filter: nil
)
  @loader = loader
  @patterns = patterns
  @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



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/orthoses/rbs_prototype_runtime.rb', line 24

def call
  @loader.call.tap do |store|
    content_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,
    )

    patterns = @patterns

    patterns =
      if patterns
        patterns.flat_map do |pattern|
          if pattern.respond_to?(:call)
            pattern.call
          else
            pattern
          end
        end
      else
        store.keys
      end
    env = Utils.rbs_environment
    merge = false
    owners_included = []
    RBS::Prototype::Runtime.new(
      patterns: patterns,
      env: env,
      merge: merge,
      owners_included: owners_included,
    ).decls.each do |decl|
      content_env << decl
    end

    content_env.write_to(store: store)
  end
end