active_method 1.2.0 → 1.3.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: 0b23c787014f849b2af42c1c7df267235e94e4b15e85de7bfe8aca97a86f6c38
4
- data.tar.gz: '02742652085c1b7dde6e0b02c416c1bd7a6be9713fe33f348e45bdb56ba01e06'
3
+ metadata.gz: b181be6c86bef5b467ce95e50c45fc7518c21e459fda43745410ec16e38263fe
4
+ data.tar.gz: 29b824f426b078e8237808012871aa355d316c291850daddc1e736576fb29850
5
5
  SHA512:
6
- metadata.gz: b99542a6f439c9758bcedcc024de0f079ddd95d43e0b71c5fd2aa88d9a02bdbbe4719cbed7bc2b6c096dda49686878c9cd3dfa41132dd1e51a7f367d2f5f9d9a
7
- data.tar.gz: 45fd84df3b3c2a5d51dcfaf73b498a335ee9cc416788b881e526b01afdfad34d90da170167b440b2ffe7c9576b0167e2c6fea717940961f77cdb45eab82381da
6
+ metadata.gz: 02ba2481e2d0ae0cfa55f31c74720b52f19ee28b753f343ebdfada18c1ee0abfb809bb43cfd50636fedd9c3815a35510eebf38c1d0a50f9c6f1a0fa7035ebc73
7
+ data.tar.gz: f3ce2172f62eb8a43be03a84602691a8d75240c001ab22c9805332f8ddc24b4e70c68c5c0c5541a22d596eb6f4d2436b83188aa0c65229c55e45384f8d48b582
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.3.0] - 2022-12-23
4
+
5
+ - Support &block
6
+
7
+ ## [1.2.1] - 2022-11-21
8
+
9
+ - Build on main branch
3
10
  ## [1.2.0] - 2022-11-21
4
11
 
5
12
  - Support `class_method`
data/README.md CHANGED
@@ -1,132 +1,78 @@
1
1
  # ActiveMethod
2
2
 
3
- Refactor your obscure method to a method object with `ActiveMethod`
3
+ Method is an object in Ruby, but we need **a real method object**. Welcome to `ActiveMethod`!
4
4
 
5
- ## Installation
5
+ - **Clean scope** without module
6
+ - **High maintainability** with tiny method objects
7
+ - Make wrting OO **easy**, then writing OO **everywhere**
6
8
 
7
- Install the gem and add to the application's Gemfile by executing:
9
+ ![](./hero.png)
8
10
 
9
- $ bundle add active_method
11
+ ## Installation
10
12
 
11
- If bundler is not being used to manage dependencies, install the gem by executing:
13
+ ```bash
14
+ $ bundle add active_method
15
+ ```
12
16
 
13
- $ gem install active_method
17
+ ## API
14
18
 
15
- ## Usage
19
+ **It just do what a method do, and nothing else!**
16
20
 
17
- Refactor `Foo#bar` to `Bar` with `ActiveMethod`
21
+ ### Define method object
18
22
 
19
23
  ```ruby
20
- class Foo
21
- def bar(a, b, c: , d:)
22
- puts "a: #{a}"
23
- puts "b: #{b}"
24
- puts "c: #{c}"
25
- puts "d: #{d}"
26
-
27
- buzz
28
- end
24
+ class User
25
+ include ActiveMethod
29
26
 
30
- def buzs
31
- puts 'buzz'
32
- end
27
+ active_method :foo
28
+ active_method :bar, MyBar
29
+ active_method :build_one, class_method: true
30
+ end
31
+
32
+ module Util
33
+ active_method :parse_url, module_function: true
33
34
  end
34
35
  ```
35
36
 
36
- Refactor to:
37
+ ### Declaring arguments
37
38
 
38
39
  ```ruby
39
- class Bar < ActiveMethod::Base
40
+ class Foo < ActiveMethod::Base
40
41
  argument :a
41
42
  argument :b, default: 2
42
43
  keyword_argument :c
43
44
  keyword_argument :d, default: 4
44
45
 
45
46
  def call
46
- puts "a: #{a}"
47
- puts "b: #{b}"
48
- puts "c: #{c}"
49
- puts "d: #{d}"
50
-
51
- foo.buzz
47
+ puts "a: #{a}, b: #{b}, c: #{c}, d: #{d}"
52
48
  end
53
49
  end
54
50
 
55
- class Foo
56
- include ActiveMethod
57
-
58
- active_method :bar
59
- end
60
-
61
- Bar.call(1)
62
- # => a: 1
63
- # => b: 2
64
- # => c: nil
65
- # => d: 4
66
- # => buzz
67
-
68
- Bar.call(1, 3)
69
- # => a: 1
70
- # => b: 3
71
- # => c: nil
72
- # => d: 4
73
- # => buzz
74
-
75
- Bar.call(1, 3, c: 6)
76
- # => a: 1
77
- # => b: 3
78
- # => c: 6
79
- # => d: 4
80
- # => buzz
81
-
82
- Bar.call(1, 3, c: 4, d: 5)
83
- # => a: 1
84
- # => b: 3
85
- # => c: 4
86
- # => d: 5
87
- # => buzz
51
+ User.new.foo('aa', 3, c: 'cc', d: 5)
52
+ #=> a: aa, b: 3, c: cc, d: 5
88
53
  ```
89
54
 
90
- ### Work on module
55
+ ### Get the owner of the method
91
56
 
92
57
  ```ruby
93
- class Hi < ActiveMethod::Base
94
- argument :name
95
-
96
- def call
97
- "Hi, #{name}"
98
- end
99
- end
100
-
101
- module Say
58
+ class User
102
59
  include ActiveMethod
103
-
104
- active_method :hi, module_function: true
60
+ attr_accessor :name
61
+ attr_accessor :fromal_name
62
+ active_method :hi
105
63
  end
106
64
 
107
- Say.hi('John')
108
- # => "Hi, John"
109
- ```
110
-
111
- ### Work as a class method
112
-
113
- ```ruby
114
- class BuildARobot < ActiveMethod::Base
115
- argument :name
116
-
65
+ class Hi < ActiveMethod::Base
117
66
  def call
118
- "#{robot_factory} build a robot called #{name}"
67
+ puts "Hi, I'm a #{@__method_owner.fromal_name}. Please call me #{user.name}"
119
68
  end
120
69
  end
121
70
 
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"
71
+ user = User.new
72
+ user.name = 'ActiveMethod'
73
+ user.fromal_name = 'method object'
74
+ user.hi
75
+ #=> Hi, I'm a method objectc, please call me ActiveMethod
130
76
  ```
131
77
 
132
78
  ## Development
data/hero.png ADDED
Binary file
@@ -17,8 +17,8 @@ module ActiveMethod
17
17
  end
18
18
  alias_method :on, :[]
19
19
 
20
- def call(*args)
21
- new(*args).call
20
+ def call(*args, &block)
21
+ new(*args).call(&block)
22
22
  end
23
23
 
24
24
  def arguments
@@ -8,10 +8,10 @@ module ActiveMethod
8
8
  @owner = owner
9
9
  end
10
10
 
11
- def call(*args)
11
+ def call(*args, &block)
12
12
  method = method_class.new(*args)
13
13
  method.__set_owner(owner)
14
- method.call
14
+ method.call(&block)
15
15
  end
16
16
 
17
17
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveMethod
4
- VERSION = "1.2.0"
4
+ VERSION = "1.3.0"
5
5
  end
data/lib/active_method.rb CHANGED
@@ -16,13 +16,13 @@ module ActiveMethod
16
16
  method_class ||= Util.constantize self, Util.camel_case(name)
17
17
 
18
18
  if options[:class_method]
19
- define_singleton_method name do |*args|
20
- method_class[self].call(*args)
19
+ define_singleton_method name do |*args, &block|
20
+ method_class[self].call(*args, &block)
21
21
  end
22
22
 
23
23
  else
24
- define_method name do |*args|
25
- method_class[self].call(*args)
24
+ define_method name do |*args, &block|
25
+ method_class[self].call(*args, &block)
26
26
  end
27
27
 
28
28
  if options[:module_function]
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.2.0
4
+ version: 1.3.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-21 00:00:00.000000000 Z
11
+ date: 2022-12-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Refactor your obscure method to a method object
14
14
  email:
@@ -23,6 +23,7 @@ files:
23
23
  - LICENSE.txt
24
24
  - README.md
25
25
  - Rakefile
26
+ - hero.png
26
27
  - lib/active_method.rb
27
28
  - lib/active_method/base.rb
28
29
  - lib/active_method/executor.rb