Class: RbsConfig::RailsConfig::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs_config/rails_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mapping:) ⇒ Generator

Returns a new instance of Generator.



16
17
18
# File 'lib/rbs_config/rails_config.rb', line 16

def initialize(mapping:)
  @mapping = mapping
end

Instance Attribute Details

#mapping ⇒ Object (readonly)

Returns the value of attribute mapping.



14
15
16
# File 'lib/rbs_config/rails_config.rb', line 14

def mapping
  @mapping
end

Instance Method Details

#generate ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rbs_config/rails_config.rb', line 20

def generate
  classes = generate_classes(mapping)
  methods = mapping.map do |key, value|
    "def #{key}: () -> #{stringify_type(key, value)}"
  end

  format <<~RBS
    module Rails
      class Application
        class Configuration
          #{classes.join("\n")}
          #{methods.join("\n")}
        end
      end

      def self.configuration: () -> Application::Configuration | ...
    end
  RBS
end