File tree Expand file tree Collapse file tree 3 files changed +29
-7
lines changed
Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Original file line number Diff line number Diff line change 33require_relative "active_method/version"
44
55module ActiveMethod
6- autoload :Base , "active_method/base"
76 autoload :Util , "active_method/util"
7+ autoload :Executor , "active_method/executor"
8+ autoload :Base , "active_method/base"
89
910 def self . included ( base )
1011 base . extend ClassMethods
@@ -15,9 +16,7 @@ def active_method(name, method_class = nil)
1516 method_class ||= Util . constantize self , Util . camel_case ( name )
1617
1718 define_method name do |*args |
18- method = method_class . new ( *args )
19- method . __set_owner ( self )
20- method . call
19+ method_class [ self ] . call ( *args )
2120 end
2221 end
2322 end
Original file line number Diff line number Diff line change @@ -12,6 +12,11 @@ def initialize(name, default: nil)
1212
1313 class << self
1414
15+ def []( owner )
16+ Executor . new ( self , owner )
17+ end
18+ alias_method :on , :[]
19+
1520 def call ( *args )
1621 new ( *args ) . call
1722 end
@@ -96,9 +101,6 @@ def initialize(*args)
96101 end
97102 end
98103
99- def call
100- end
101-
102104 def __set_owner ( owner )
103105 @__method_owner = owner
104106
@@ -108,6 +110,9 @@ def __set_owner(owner)
108110 end
109111 end
110112
113+ def call
114+ end
115+
111116 private
112117
113118 def arguments
Original file line number Diff line number Diff line change 1+ module ActiveMethod
2+ class Executor
3+
4+ attr_reader :method_class , :owner
5+
6+ def initialize ( klass , owner )
7+ @method_class = klass
8+ @owner = owner
9+ end
10+
11+ def call ( *args )
12+ method = method_class . new ( *args )
13+ method . __set_owner ( owner )
14+ method . call
15+ end
16+
17+ end
18+ end
You can’t perform that action at this time.
0 commit comments