active_method 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b181be6c86bef5b467ce95e50c45fc7518c21e459fda43745410ec16e38263fe
4
- data.tar.gz: 29b824f426b078e8237808012871aa355d316c291850daddc1e736576fb29850
3
+ metadata.gz: 4fab4e210742187e5e4a9beec876bd7fda51e8c35f5ead5727dc0ca70312f11b
4
+ data.tar.gz: fbcbb425512417164afb2dcf7b109a08285ba703cecb19eb8f65db013f2f08b9
5
5
  SHA512:
6
- metadata.gz: 02ba2481e2d0ae0cfa55f31c74720b52f19ee28b753f343ebdfada18c1ee0abfb809bb43cfd50636fedd9c3815a35510eebf38c1d0a50f9c6f1a0fa7035ebc73
7
- data.tar.gz: f3ce2172f62eb8a43be03a84602691a8d75240c001ab22c9805332f8ddc24b4e70c68c5c0c5541a22d596eb6f4d2436b83188aa0c65229c55e45384f8d48b582
6
+ metadata.gz: a1195ca092a70e1f51147b7d5db82910e46af2ae2a4923800012a6f26d17fbd8d01e2c0f342ef79a2d44255f2524d02d5557a55c964633648358d466af276967
7
+ data.tar.gz: bd67e7208be9c451d1e1d72e0d5d85be81ae49143093d9325c36218136226481832d45e1cbd621c9ad4d4269349d16ff211a4254065d99c7edd7d802abd2c746
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.4.0] - 2024-06-23
4
+
5
+ - Support customize method owner name
6
+
3
7
  ## [1.3.0] - 2022-12-23
4
8
 
5
9
  - 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
 
@@ -29,9 +29,14 @@ module ActiveMethod
29
29
  class_variable_get(:@@keyword_arguments)
30
30
  end
31
31
 
32
+ def owner_name
33
+ class_variable_get(:@@owner_name)
34
+ end
35
+
32
36
  def inherited(subclass)
33
37
  subclass.init_arguments
34
38
  subclass.init_keyword_arguments
39
+ subclass.init_owner_name
35
40
  end
36
41
 
37
42
  protected
@@ -42,6 +47,8 @@ module ActiveMethod
42
47
  parse_argument(method_name, *args)
43
48
  when 'keyword_argument'
44
49
  parse_keyword_argument(*args)
50
+ when 'owner'
51
+ parse_method_owner(*args)
45
52
  else
46
53
  super
47
54
  end
@@ -67,6 +74,10 @@ module ActiveMethod
67
74
  end
68
75
  end
69
76
 
77
+ def parse_method_owner(name)
78
+ class_variable_set(:@@owner_name, name)
79
+ end
80
+
70
81
  def init_arguments
71
82
  return if self.class_variable_defined?(:@@arguments)
72
83
 
@@ -78,6 +89,12 @@ module ActiveMethod
78
89
 
79
90
  self.class_variable_set(:@@keyword_arguments, [])
80
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
81
98
  end
82
99
 
83
100
  def initialize(*args)
@@ -104,9 +121,13 @@ module ActiveMethod
104
121
  def __set_owner(owner)
105
122
  @__method_owner = owner
106
123
 
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
124
+ @__owner_name = self.class.owner_name
125
+ if @__owner_name.nil?
126
+ klass = owner.is_a?(Class) ? owner : owner.class
127
+ @__owner_name = Util.snake_case(klass.name.split("::").last)
128
+ end
129
+
130
+ self.define_singleton_method @__owner_name do
110
131
  @__method_owner
111
132
  end
112
133
  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.4.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.4.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-07-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Refactor your obscure method to a method object
14
14
  email: