active_method 1.1.0 → 1.2.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: '09981bf259603ed5a3702d558f61812780801c59af7dc1f61e0a8a4d9785e211'
4
- data.tar.gz: 6ac6cc4ab0f822592bd355f2d57cb9c7bddfd5d743685e2e20115da8a6f6eae3
3
+ metadata.gz: 0b23c787014f849b2af42c1c7df267235e94e4b15e85de7bfe8aca97a86f6c38
4
+ data.tar.gz: '02742652085c1b7dde6e0b02c416c1bd7a6be9713fe33f348e45bdb56ba01e06'
5
5
  SHA512:
6
- metadata.gz: 44df9e385113755724745f2fc0a022b71d44611b7443f627dc04a78dc3b26d529259315ee8eaada7172fc6791a2eab22b0f2ee9c368b1c933d1c25c2314ee1b1
7
- data.tar.gz: eb4cb181d3112ae398aaae750a7bf431f71265d21f0b6084fc804bd4368e78bb07fbabc14bd756a00f1e840299e1d2e9ea5521cb03591b4e0ba781043c88b9a2
6
+ metadata.gz: b99542a6f439c9758bcedcc024de0f079ddd95d43e0b71c5fd2aa88d9a02bdbbe4719cbed7bc2b6c096dda49686878c9cd3dfa41132dd1e51a7f367d2f5f9d9a
7
+ data.tar.gz: 45fd84df3b3c2a5d51dcfaf73b498a335ee9cc416788b881e526b01afdfad34d90da170167b440b2ffe7c9576b0167e2c6fea717940961f77cdb45eab82381da
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.2.0] - 2022-11-21
4
+
5
+ - Support `class_method`
6
+
7
+ ## [1.1.1] - 2022-10-08
8
+
9
+ - Change owner method define from `self.calss.define_method` to `self.define_singleton_method`
10
+
3
11
  ## [1.1.0] - 2022-10-08
4
12
 
5
13
  - Support `module_function`
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,8 +104,9 @@ 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)
108
- self.class.define_method instance_name do
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
109
110
  @__method_owner
110
111
  end
111
112
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveMethod
4
- VERSION = "1.1.0"
4
+ VERSION = "1.2.0"
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.0
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-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: