Class: Steep::Index::RBSIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/steep/index/rbs_index.rb

Defined Under Namespace

Classes: Builder, ConstantEntry, GlobalEntry, MethodEntry, TypeEntry

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRBSIndex

Returns a new instance of RBSIndex.



132
133
134
135
136
137
# File 'lib/steep/index/rbs_index.rb', line 132

def initialize()
  @type_index = {}
  @method_index = {}
  @const_index = {}
  @global_index = {}
end

Instance Attribute Details

#const_indexObject (readonly)

Returns the value of attribute const_index.



129
130
131
# File 'lib/steep/index/rbs_index.rb', line 129

def const_index
  @const_index
end

#global_indexObject (readonly)

Returns the value of attribute global_index.



130
131
132
# File 'lib/steep/index/rbs_index.rb', line 130

def global_index
  @global_index
end

#method_indexObject (readonly)

Returns the value of attribute method_index.



128
129
130
# File 'lib/steep/index/rbs_index.rb', line 128

def method_index
  @method_index
end

#type_indexObject (readonly)

Returns the value of attribute type_index.



127
128
129
# File 'lib/steep/index/rbs_index.rb', line 127

def type_index
  @type_index
end

Instance Method Details

#add_constant_declaration(const_name, decl) ⇒ Object



173
174
175
# File 'lib/steep/index/rbs_index.rb', line 173

def add_constant_declaration(const_name, decl)
  entry(const_name: const_name).add_declaration(decl)
end

#add_global_declaration(global_name, decl) ⇒ Object



177
178
179
# File 'lib/steep/index/rbs_index.rb', line 177

def add_global_declaration(global_name, decl)
  entry(global_name: global_name).add_declaration(decl)
end

#add_method_declaration(method_name, member) ⇒ Object



169
170
171
# File 'lib/steep/index/rbs_index.rb', line 169

def add_method_declaration(method_name, member)
  entry(method_name: method_name).add_declaration(member)
end

#add_type_declaration(type_name, declaration) ⇒ Object



165
166
167
# File 'lib/steep/index/rbs_index.rb', line 165

def add_type_declaration(type_name, declaration)
  entry(type_name: type_name).add_declaration(declaration)
end

#add_type_reference(type_name, ref) ⇒ Object



190
191
192
# File 'lib/steep/index/rbs_index.rb', line 190

def add_type_reference(type_name, ref)
  entry(type_name: type_name).add_reference(ref)
end

#each_declaration(type_name: nil, method_name: nil, const_name: nil, global_name: nil, &block) ⇒ Object



181
182
183
184
185
186
187
188
# File 'lib/steep/index/rbs_index.rb', line 181

def each_declaration(type_name: nil, method_name: nil, const_name: nil, global_name: nil, &block)
  if block
    entry = __skip__ = entry(type_name: type_name, method_name: method_name, const_name: const_name, global_name: global_name)
    entry.declarations.each(&block)
  else
    enum_for(:each_declaration, type_name: type_name, method_name: method_name, const_name: const_name, global_name: global_name)
  end
end

#each_entry(&block) ⇒ Object



154
155
156
157
158
159
160
161
162
163
# File 'lib/steep/index/rbs_index.rb', line 154

def each_entry(&block)
  if block
    type_index.each_value(&block)
    method_index.each_value(&block)
    const_index.each_value(&block)
    global_index.each_value(&block)
  else
    enum_for(:each_entry)
  end
end

#each_reference(type_name:, &block) ⇒ Object



194
195
196
197
198
199
200
201
202
203
# File 'lib/steep/index/rbs_index.rb', line 194

def each_reference(type_name:, &block)
  if block
    case
    when type_name
      entry(type_name: type_name).references.each(&block)
    end
  else
    enum_for(:each_reference, type_name: type_name)
  end
end

#entry(type_name: nil, method_name: nil, const_name: nil, global_name: nil) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/steep/index/rbs_index.rb', line 139

def entry(type_name: nil, method_name: nil, const_name: nil, global_name: nil)
  case
  when type_name
    type_index[type_name] ||= TypeEntry.new(type_name: type_name)
  when method_name
    method_index[method_name] ||= MethodEntry.new(method_name: method_name)
  when const_name
    const_index[const_name] ||= ConstantEntry.new(const_name: const_name)
  when global_name
    global_index[global_name] ||= GlobalEntry.new(global_name: global_name)
  else
    raise
  end
end