Class: RbsActiverecord::Generator::Scopes

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, declarations) ⇒ Scopes

Returns a new instance of Scopes.



11
12
13
14
# File 'lib/rbs_activerecord/generator/scopes.rb', line 11

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

Instance Attribute Details

#declarationsObject (readonly)

: Array



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

def declarations
  @declarations
end

#modelObject (readonly)

: RbsActiverecord::Model



6
7
8
# File 'lib/rbs_activerecord/generator/scopes.rb', line 6

def model
  @model
end

Instance Method Details

#generateObject

: String



16
17
18
19
20
21
22
# File 'lib/rbs_activerecord/generator/scopes.rb', line 16

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