active_method 1.1.1 → 1.2.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 +4 -4
- data/CHANGELOG.md +4 -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: 0b23c787014f849b2af42c1c7df267235e94e4b15e85de7bfe8aca97a86f6c38
|
4
|
+
data.tar.gz: '02742652085c1b7dde6e0b02c416c1bd7a6be9713fe33f348e45bdb56ba01e06'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b99542a6f439c9758bcedcc024de0f079ddd95d43e0b71c5fd2aa88d9a02bdbbe4719cbed7bc2b6c096dda49686878c9cd3dfa41132dd1e51a7f367d2f5f9d9a
|
7
|
+
data.tar.gz: 45fd84df3b3c2a5d51dcfaf73b498a335ee9cc416788b881e526b01afdfad34d90da170167b440b2ffe7c9576b0167e2c6fea717940961f77cdb45eab82381da
|
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.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-
|
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:
|