Class: RbsActiverecord::Generator::Enum::Mappings

Inherits:
Base
  • Object
show all
Defined in:
lib/rbs_activerecord/generator/enum/mappings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, declarations) ⇒ Mappings

Returns a new instance of Mappings.



12
13
14
15
16
17
# File 'lib/rbs_activerecord/generator/enum/mappings.rb', line 12

def initialize(model, declarations) #: void
  @model = model
  @declarations = declarations.fetch(model.klass.name.to_s, [])

  super()
end

Instance Attribute Details

#declarationsObject (readonly)

: Array



8
9
10
# File 'lib/rbs_activerecord/generator/enum/mappings.rb', line 8

def declarations
  @declarations
end

#modelObject (readonly)

: RbsActiverecord::Model



7
8
9
# File 'lib/rbs_activerecord/generator/enum/mappings.rb', line 7

def model
  @model
end

Instance Method Details

#generateObject

: String



19
20
21
22
23
24
25
# File 'lib/rbs_activerecord/generator/enum/mappings.rb', line 19

def generate #: String
  <<~RBS.strip
    module GeneratedEnumMappingMethods
      #{enums.map { |node| enum(node) }.join("\n")}
    end
  RBS
end