Class: RbsActiverecord::Generator::Enum::Scopes

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, declarations) ⇒ Scopes

Returns a new instance of Scopes.



12
13
14
15
16
17
# File 'lib/rbs_activerecord/generator/enum/scopes.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/scopes.rb', line 8

def declarations
  @declarations
end

#modelObject (readonly)

: RbsActiverecord::Model



7
8
9
# File 'lib/rbs_activerecord/generator/enum/scopes.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/scopes.rb', line 19

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