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 +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +21 -0
- data/lib/active_method/base.rb +2 -1
- data/lib/active_method/version.rb +1 -1
- data/lib/active_method.rb +13 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfbff213fde68c49d9a524d227aa9dc651160bbe5b72973b62991d718e092d08
|
4
|
+
data.tar.gz: 2b40034fb74458e547196d8c990ca6cf814950c2be638aefdd9829df4c10fcc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee417c29294f6ef9ce18f397eddc770c420ca370d460fa4e831708f3f8e673493971eae1fc6522776c7a440d3721eb1308584dbc1310cb8b259c096040822012
|
7
|
+
data.tar.gz: 50a1753a7745ab0248fcbc54164a3a93b9b8bfccb446fe2bc1b12b69bb2f4b61e5dd92d781e5ea64e1eb32ad7e595486d64a03481307afab67c92c2a4553c26f
|
data/CHANGELOG.md
CHANGED
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
|
data/lib/active_method/base.rb
CHANGED
@@ -104,7 +104,8 @@ module ActiveMethod
|
|
104
104
|
def __set_owner(owner)
|
105
105
|
@__method_owner = owner
|
106
106
|
|
107
|
-
|
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
|
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
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
23
|
-
|
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.
|
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-
|
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:
|