Module: RbsRails::Util

Extended by:
Util, Util
Included in:
Util
Defined in:
lib/rbs_rails/util.rb,
lib/rbs_rails/util/file_writer.rb,
sig/rbs_rails/util.rbs,
sig/rbs_rails/util/file_writer.rbs

Defined Under Namespace

Classes: FileWriter

Constant Summary collapse

MODULE_NAME =

: UnboundMethod

Returns:

  • (UnboundMethod)
Module.instance_method(:name)

Instance Method Summary collapse

Instance Method Details

#format_rbs(rbs) ⇒ String

Parameters:

  • rbs (String)

Returns:

  • (String)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rbs_rails/util.rb', line 20

def format_rbs(rbs) #: String
  decls =
    if Gem::Version.new('3') <= Gem::Version.new(RBS::VERSION)
      parsed = _ = RBS::Parser.parse_signature(rbs)
      parsed[1] + parsed[2]
    else
      # TODO: Remove this type annotation when rbs_rails drops support of RBS 2.x.
      # @type var parsed: [RBS::Declarations::t]
      parsed = _ = RBS::Parser.parse_signature(rbs)
    end

  StringIO.new.tap do |io|
    RBS::Writer.new(out: io).write(decls)
  end.string
end

#module_name(mod, abs: true) ⇒ String

Parameters:

  • mod (Module)
  • abs: (boolish) (defaults to: true)

Returns:

  • (String)


13
14
15
16
17
# File 'lib/rbs_rails/util.rb', line 13

def module_name(mod, abs: true) #: String
  name = MODULE_NAME.bind_call(mod)
  name ="::#{name}" if abs
  name
end