active_method 1.3.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b181be6c86bef5b467ce95e50c45fc7518c21e459fda43745410ec16e38263fe
4
- data.tar.gz: 29b824f426b078e8237808012871aa355d316c291850daddc1e736576fb29850
3
+ metadata.gz: 8c0688ad78d8a0b27bd65cb414eb2815684a86e415a50de9858f1e9a0bccaa91
4
+ data.tar.gz: f4d248efb0782cf91cd1476537dbc31bf3b43373813bae9dd25444651a8d9dae
5
5
  SHA512:
6
- metadata.gz: 02ba2481e2d0ae0cfa55f31c74720b52f19ee28b753f343ebdfada18c1ee0abfb809bb43cfd50636fedd9c3815a35510eebf38c1d0a50f9c6f1a0fa7035ebc73
7
- data.tar.gz: f3ce2172f62eb8a43be03a84602691a8d75240c001ab22c9805332f8ddc24b4e70c68c5c0c5541a22d596eb6f4d2436b83188aa0c65229c55e45384f8d48b582
6
+ metadata.gz: 9a4aaea9111161b1a672ee7eecced37c7654c0ec684f82f3b4469df8577dd050fe1066a7559561094d9faf62daa8c53e3fb19a43f54645bca4667a5d849edc90
7
+ data.tar.gz: adeb5ec18322b51f25bfd998859329b246cf5d2cc06818ab93e09e040dd9ddf10959ec72be56aa6f9452eb61c605c19d08af95d37da1a31efc4aa94aec9167d0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.5.0] - 2024-12-18
4
+
5
+ - Support inheritance
6
+
7
+ ## [1.4.0] - 2024-06-23
8
+
9
+ - Support customize method owner name
10
+
3
11
  ## [1.3.0] - 2022-12-23
4
12
 
5
13
  - Support &block
data/README.md CHANGED
@@ -52,7 +52,7 @@ User.new.foo('aa', 3, c: 'cc', d: 5)
52
52
  #=> a: aa, b: 3, c: cc, d: 5
53
53
  ```
54
54
 
55
- ### Get the owner of the method
55
+ ### Customize the owner name of the method
56
56
 
57
57
  ```ruby
58
58
  class User
@@ -63,8 +63,10 @@ class User
63
63
  end
64
64
 
65
65
  class Hi < ActiveMethod::Base
66
+ onwer :support
67
+
66
68
  def call
67
- puts "Hi, I'm a #{@__method_owner.fromal_name}. Please call me #{user.name}"
69
+ puts "Hi, I'm a #{support.fromal_name}. Please call me #{user.name}"
68
70
  end
69
71
  end
70
72
 
@@ -22,16 +22,17 @@ module ActiveMethod
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
- def inherited(subclass)
33
- subclass.init_arguments
34
- subclass.init_keyword_arguments
32
+ def owner_name
33
+ return @owner_name unless @owner_name.nil?
34
+ return if self == ActiveMethod::Base
35
+ superclass.owner_name
35
36
  end
36
37
 
37
38
  protected
@@ -42,6 +43,8 @@ module ActiveMethod
42
43
  parse_argument(method_name, *args)
43
44
  when 'keyword_argument'
44
45
  parse_keyword_argument(*args)
46
+ when 'owner'
47
+ parse_method_owner(*args)
45
48
  else
46
49
  super
47
50
  end
@@ -67,17 +70,10 @@ module ActiveMethod
67
70
  end
68
71
  end
69
72
 
70
- def init_arguments
71
- return if self.class_variable_defined?(:@@arguments)
72
-
73
- self.class_variable_set(:@@arguments, {})
73
+ def parse_method_owner(name)
74
+ @owner_name = name
74
75
  end
75
76
 
76
- def init_keyword_arguments
77
- return if self.class_variable_defined?(:@@keyword_arguments)
78
-
79
- self.class_variable_set(:@@keyword_arguments, [])
80
- end
81
77
  end
82
78
 
83
79
  def initialize(*args)
@@ -104,9 +100,13 @@ module ActiveMethod
104
100
  def __set_owner(owner)
105
101
  @__method_owner = owner
106
102
 
107
- klass = owner.is_a?(Class) ? owner : owner.class
108
- instance_name = Util.snake_case(klass.name.split("::").last)
109
- self.define_singleton_method instance_name do
103
+ @__owner_name = self.class.owner_name
104
+ if @__owner_name.nil?
105
+ klass = owner.is_a?(Class) ? owner : owner.class
106
+ @__owner_name = Util.snake_case(klass.name.split("::").last)
107
+ end
108
+
109
+ self.define_singleton_method @__owner_name do
110
110
  @__method_owner
111
111
  end
112
112
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveMethod
4
- VERSION = "1.3.0"
4
+ VERSION = "1.5.0"
5
5
  end
data/matrixeval.yml CHANGED
@@ -18,9 +18,15 @@ matrix:
18
18
  container:
19
19
  image: ruby:3.0.4
20
20
  - key: 3.1
21
- default: true
22
21
  container:
23
22
  image: ruby:3.1.2
23
+ - key: 3.2
24
+ container:
25
+ image: ruby:3.2.4
26
+ - key: 3.3
27
+ default: true
28
+ container:
29
+ image: ruby:3.3.4
24
30
  # - key: jruby-9.3
25
31
  # container:
26
32
  # image: jruby:9.3
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_method
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hopper Gee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-23 00:00:00.000000000 Z
11
+ date: 2024-12-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Refactor your obscure method to a method object
14
14
  email: