File tree Expand file tree Collapse file tree 4 files changed +58
-28
lines changed Expand file tree Collapse file tree 4 files changed +58
-28
lines changed Original file line number Diff line number Diff line change 1
1
## [ Unreleased]
2
2
3
+ ## [ 1.5.0] - 2024-12-18
4
+
5
+ - Support inheritance
6
+
3
7
## [ 1.4.0] - 2024-06-23
4
8
5
9
- Support customize method owner name
Original file line number Diff line number Diff line change @@ -22,21 +22,17 @@ def call(*args, &block)
22
22
end
23
23
24
24
def arguments
25
- class_variable_get ( :@@ arguments)
25
+ @ arguments ||= { }
26
26
end
27
27
28
28
def keyword_arguments
29
- class_variable_get ( :@@ keyword_arguments)
29
+ @ keyword_arguments ||= [ ]
30
30
end
31
31
32
32
def owner_name
33
- class_variable_get ( :@@owner_name )
34
- end
35
-
36
- def inherited ( subclass )
37
- subclass . init_arguments
38
- subclass . init_keyword_arguments
39
- subclass . init_owner_name
33
+ return @owner_name unless @owner_name . nil?
34
+ return if self == ActiveMethod ::Base
35
+ superclass . owner_name
40
36
end
41
37
42
38
protected
@@ -75,26 +71,9 @@ def parse_keyword_argument(name, opts = {})
75
71
end
76
72
77
73
def parse_method_owner ( name )
78
- class_variable_set ( :@@owner_name , name )
79
- end
80
-
81
- def init_arguments
82
- return if self . class_variable_defined? ( :@@arguments )
83
-
84
- self . class_variable_set ( :@@arguments , { } )
74
+ @owner_name = name
85
75
end
86
76
87
- def init_keyword_arguments
88
- return if self . class_variable_defined? ( :@@keyword_arguments )
89
-
90
- self . class_variable_set ( :@@keyword_arguments , [ ] )
91
- end
92
-
93
- def init_owner_name
94
- return if self . class_variable_defined? ( :@@owner_name )
95
-
96
- self . class_variable_set ( :@@owner_name , nil )
97
- end
98
77
end
99
78
100
79
def initialize ( *args )
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
module ActiveMethod
4
- VERSION = "1.4 .0"
4
+ VERSION = "1.5 .0"
5
5
end
Original file line number Diff line number Diff line change @@ -261,4 +261,51 @@ class Laptop
261
261
assert laptop . off
262
262
end
263
263
264
+ ################
265
+ # .active_method with inheritance
266
+ ################
267
+
268
+ class DemoAPIBase < ActiveMethod ::Base
269
+ owner :client
270
+ end
271
+
272
+ class GetA < DemoAPIBase
273
+ argument :id
274
+
275
+ def call
276
+ puts "Request GET: /a"
277
+ end
278
+ end
279
+
280
+ class GetB < DemoAPIBase
281
+ keyword_argument :first
282
+ keyword_argument :per
283
+
284
+ def call
285
+ puts "Request GET: /b"
286
+ end
287
+ end
288
+
289
+ class Client
290
+ include ActiveMethod
291
+ active_method :get_a
292
+ active_method :get_b
293
+ end
294
+
295
+ it ".active_method can orgianize with a Base methd" do
296
+ get_a_arguments = GetA . arguments . values
297
+ assert_equal 1 , get_a_arguments . count
298
+ assert_equal :id , get_a_arguments [ 0 ] . name
299
+ get_a_keyword_arguments = GetA . keyword_arguments
300
+ assert_equal 0 , get_a_keyword_arguments . count
301
+ assert_equal :client , GetA . owner_name
302
+
303
+ get_b_arguments = GetB . arguments . values
304
+ assert_equal 0 , get_b_arguments . count
305
+ get_b_keyword_arguments = GetB . keyword_arguments
306
+ assert_equal :first , get_b_keyword_arguments [ 0 ] . name
307
+ assert_equal :per , get_b_keyword_arguments [ 1 ] . name
308
+ assert_equal :client , GetB . owner_name
309
+ end
310
+
264
311
end
You can’t perform that action at this time.
0 commit comments