Class: RbsActiverecord::Parser::IncludeExpander

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs_activerecord/parser/include_expander.rb,
lib/rbs_activerecord/parser/include_expander/module.rb

Defined Under Namespace

Classes: Module

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, declarations) ⇒ IncludeExpander

Returns a new instance of IncludeExpander.



17
18
19
20
# File 'lib/rbs_activerecord/parser/include_expander.rb', line 17

def initialize(model, declarations) #: void
  @model = model
  @declarations = declarations
end

Instance Attribute Details

#declarationsObject (readonly)

: Hash[String, Array]



13
14
15
# File 'lib/rbs_activerecord/parser/include_expander.rb', line 13

def declarations
  @declarations
end

#modelObject (readonly)

: RbsActiverecord::Model



12
13
14
# File 'lib/rbs_activerecord/parser/include_expander.rb', line 12

def model
  @model
end

Class Method Details

.expand(model, declarations) ⇒ Object



8
9
10
# File 'lib/rbs_activerecord/parser/include_expander.rb', line 8

def self.expand(model, declarations) #: void
  new(model, declarations).expand
end

Instance Method Details

#expandObject

: void



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rbs_activerecord/parser/include_expander.rb', line 22

def expand #: void
  declarations.each_value do |decls|
    loop do
      index = decls.index { |node| node.name == :include }
      break unless index

      included_module = decls.delete_at(index)
      included_blocks = included_blocks_for(included_module)
      included_blocks.reverse_each do |included|
        decls.insert(index, *block_body_of(included))
      end
    end
  end
end