Skip to content

Commit 006e26a

Browse files
committed
add extend_modules
1 parent d7083f9 commit 006e26a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/helpers/parse_ruby.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
if node.receiver.nil? && node.name == :prepend && definitions.current_node_type == "class" && !node.arguments.nil? && %i[constant_read_node constant_path_node].include?(node.arguments.arguments.first.type)
5151
definitions.add_prepend_module(node.arguments.arguments.first.to_source)
5252
end
53+
if node.receiver.nil? && node.name == :extend && definitions.current_node_type == "class" && !node.arguments.nil? && %i[constant_read_node constant_path_node].include?(node.arguments.arguments.first.type)
54+
definitions.add_extend_module(node.arguments.arguments.first.to_source)
55+
end
5356
end
5457

5558
add_callback :call_node, at: 'start' do |node|
@@ -142,6 +145,10 @@ def add_prepend_module(name)
142145
@node.prepend_modules.push(name)
143146
end
144147

148+
def add_extend_module(name)
149+
@node.extend_modules.push(name)
150+
end
151+
145152
def add_method(name)
146153
method_definition = MethodDefinition.new(parent: @node, name: name)
147154
@node.methods.push(method_definition)
@@ -286,7 +293,7 @@ def to_h
286293
end
287294

288295
class ClassDefinition < BaseDefinition
289-
attr_reader :parent, :name, :superclass, :modules, :classes, :methods, :static_methods, :constants, :include_modules, :prepend_modules
296+
attr_reader :parent, :name, :superclass, :modules, :classes, :methods, :static_methods, :constants, :include_modules, :prepend_modules, :extend_modules
290297
attr_accessor :singleton, :ancestors
291298

292299
def initialize(parent:, name:, superclass:)
@@ -300,6 +307,7 @@ def initialize(parent:, name:, superclass:)
300307
@constants = []
301308
@include_modules = []
302309
@prepend_modules = []
310+
@extend_modules = []
303311
@ansestors = []
304312
end
305313

@@ -314,6 +322,7 @@ def to_h
314322
constants: @constants,
315323
include_modules: @include_modules,
316324
prepend_modules: @prepend_modules,
325+
extend_modules: @extend_modules,
317326
singleton: @singleton&.to_h,
318327
ancestors: @ancestors
319328
}

spec/helpers/parse_ruby_spec.rb

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Synvert
1616
class User
1717
include Trackable
1818
prepend Authenticatable
19+
extend ClassMethods
1920
2021
ROLES = %w[user admin].freeze
2122
@@ -66,6 +67,7 @@ def user_type
6667
constants: [],
6768
include_modules: [],
6869
prepend_modules: [],
70+
extend_modules: [],
6971
singleton: nil,
7072
ancestors: ["Synvert::User", "Authenticatable", "Trackable"]
7173
},
@@ -90,6 +92,7 @@ def user_type
9092
constants: [{ name: "ROLES" }],
9193
include_modules: ["Trackable"],
9294
prepend_modules: ["Authenticatable"],
95+
extend_modules: ["ClassMethods"],
9396
ancestors: ["Authenticatable", "Trackable"]
9497
}
9598
],

0 commit comments

Comments
 (0)