active_method 1.1.1 → 1.2.1

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: 403381f7108f07fea213db2b68c9abc71277b1e50e523a7c15118920c186bbd5
4
- data.tar.gz: e87f9c937daf923d37934de40d04bb24adecc5c2bdcd8ce2eadbe7d3d302df27
3
+ metadata.gz: cfbff213fde68c49d9a524d227aa9dc651160bbe5b72973b62991d718e092d08
4
+ data.tar.gz: 2b40034fb74458e547196d8c990ca6cf814950c2be638aefdd9829df4c10fcc2
5
5
  SHA512:
6
- metadata.gz: e64c462061a8e6e574ebf345ee48cd4a450925acc6260b2c1ffa9f4d905bf5c9c72c773a6023eefc0d6805798d642285eaee59f7d946adaec2cefa0bb5306c93
7
- data.tar.gz: 350d6b978759a527f0a613b292297c361f939e2081b40721d9693baed446f5918ea63065fe2f3437d965a392b5d1d5e95f6377e818985f11e4429e924fd28567
6
+ metadata.gz: ee417c29294f6ef9ce18f397eddc770c420ca370d460fa4e831708f3f8e673493971eae1fc6522776c7a440d3721eb1308584dbc1310cb8b259c096040822012
7
+ data.tar.gz: 50a1753a7745ab0248fcbc54164a3a93b9b8bfccb446fe2bc1b12b69bb2f4b61e5dd92d781e5ea64e1eb32ad7e595486d64a03481307afab67c92c2a4553c26f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.2.1] - 2022-11-21
4
+
5
+ - Build on main branch
6
+ ## [1.2.0] - 2022-11-21
7
+
8
+ - Support `class_method`
9
+
3
10
  ## [1.1.1] - 2022-10-08
4
11
 
5
12
  - Change owner method define from `self.calss.define_method` to `self.define_singleton_method`
data/README.md CHANGED
@@ -108,6 +108,27 @@ Say.hi('John')
108
108
  # => "Hi, John"
109
109
  ```
110
110
 
111
+ ### Work as a class method
112
+
113
+ ```ruby
114
+ class BuildARobot < ActiveMethod::Base
115
+ argument :name
116
+
117
+ def call
118
+ "#{robot_factory} build a robot called #{name}"
119
+ end
120
+ end
121
+
122
+ class RobotFactory
123
+ include ActiveMethod
124
+
125
+ active_method :build_a_robot, class_method: true
126
+ end
127
+
128
+ RobotFactory.build_a_robot
129
+ # => "RobotFactory build a robot called B-2"
130
+ ```
131
+
111
132
  ## Development
112
133
 
113
134
  ```bash
@@ -104,7 +104,8 @@ module ActiveMethod
104
104
  def __set_owner(owner)
105
105
  @__method_owner = owner
106
106
 
107
- instance_name = Util.snake_case(owner.class.name.split("::").last)
107
+ klass = owner.is_a?(Class) ? owner : owner.class
108
+ instance_name = Util.snake_case(klass.name.split("::").last)
108
109
  self.define_singleton_method instance_name do
109
110
  @__method_owner
110
111
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveMethod
4
- VERSION = "1.1.1"
4
+ VERSION = "1.2.1"
5
5
  end
data/lib/active_method.rb CHANGED
@@ -15,13 +15,21 @@ module ActiveMethod
15
15
  def active_method(name, method_class = nil, **options)
16
16
  method_class ||= Util.constantize self, Util.camel_case(name)
17
17
 
18
- define_method name do |*args|
19
- method_class[self].call(*args)
20
- end
18
+ if options[:class_method]
19
+ define_singleton_method name do |*args|
20
+ method_class[self].call(*args)
21
+ end
22
+
23
+ else
24
+ define_method name do |*args|
25
+ method_class[self].call(*args)
26
+ end
21
27
 
22
- if options[:module_function]
23
- module_function name
28
+ if options[:module_function]
29
+ module_function name
30
+ end
24
31
  end
32
+
25
33
  end
26
34
  end
27
35
  end
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.1.1
4
+ version: 1.2.1
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-10-08 00:00:00.000000000 Z
11
+ date: 2022-11-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Refactor your obscure method to a method object
14
14
  email: