reverse_parameters 0.4.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/README.md +15 -0
- data/lib/reverse_parameters/core_ext/method.rb +6 -0
- data/lib/reverse_parameters/core_ext/unbound_method.rb +6 -0
- data/lib/reverse_parameters/core_ext.rb +2 -0
- data/lib/reverse_parameters/version.rb +1 -1
- data/lib/reverse_parameters.rb +11 -14
- data/reverse_parameters.gemspec +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdf9c667689874d90a1054cc41df3113bcaafd35
|
4
|
+
data.tar.gz: 18f492d6d41851a951832e2ee1092090f4ae411f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab20dbc01afe4bbb3f2f0063719be8ea0b556f73a459a6bf1a5159c9bef5efffa21b1e789d7d31947fc66318b314c6145afa8ab3dbd95d9dc419a25a24f13461
|
7
|
+
data.tar.gz: da12846f06e9da789f2da0ffb1f0b585cacdf6a359ec81dfe725f47ecd08a618b68f60106d0be7348702424327d5945561a9d4aceb68ace4abc8747b66b5e60e
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
-
##
|
1
|
+
## 1.0.0 - 2016-03-24
|
2
|
+
|
3
|
+
### API Changes
|
4
|
+
- ReverseParameters.new keyword arg :blocks_as_values moved to `ReverseParameters#arguments(blocks_as_values: [true, false])`
|
5
|
+
|
6
|
+
### Enhancement
|
7
|
+
- CoreExt to Ruby Code (Monkey Patch) `Method#reverse_parameters` and `UnboundMethod#reverse_parameters`. This is not required by default, to use `require 'reverse_parameters/core_ext'`.
|
8
|
+
|
9
|
+
## 0.4.0 - 2016-03-14
|
2
10
|
|
3
11
|
### Enhancement
|
4
12
|
- Add the ability to pass blocks as values with the options blocks_as_values: true given in the initializer.
|
data/README.md
CHANGED
@@ -43,6 +43,21 @@ method(:example_method).parameters
|
|
43
43
|
#=> [[:keyreq, :named_param]]
|
44
44
|
```
|
45
45
|
|
46
|
+
### Monkey Patch to Ruby Core
|
47
|
+
|
48
|
+
*`Method` and `UnboundMethod`*
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
require 'reverse_parameters/core_ext'
|
52
|
+
|
53
|
+
def example_method(named_param:)
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
method(:example_method).reverse_parameters.arguments.to_s
|
58
|
+
#=> "named_param: named_param"
|
59
|
+
```
|
60
|
+
|
46
61
|
To learn more about ruby's parameters method read [Inspecting Method Parameters in Ruby 2.2.3](https://www.rubyplus.com/articles/2721) by RubyPlus.com
|
47
62
|
|
48
63
|
|
data/lib/reverse_parameters.rb
CHANGED
@@ -3,18 +3,7 @@ require "reverse_parameters/version"
|
|
3
3
|
class ReverseParameters
|
4
4
|
|
5
5
|
# @param [Proc, Array] input
|
6
|
-
|
7
|
-
# @example
|
8
|
-
# def my_method(&block)
|
9
|
-
# end
|
10
|
-
#
|
11
|
-
# ReverseParameters.new(method(:my_method), blocks_as_values: true).arguments.to_s
|
12
|
-
# #=> "block"
|
13
|
-
#
|
14
|
-
# # ReverseParameters.new(method(:my_method)).to_s
|
15
|
-
# #=> "&block"
|
16
|
-
def initialize(input, blocks_as_values: false)
|
17
|
-
@blocks_as_values = blocks_as_values
|
6
|
+
def initialize(input)
|
18
7
|
if input.respond_to?(:to_proc)
|
19
8
|
@params = input.to_proc.parameters
|
20
9
|
elsif input.respond_to?(:to_ary)
|
@@ -32,12 +21,20 @@ class ReverseParameters
|
|
32
21
|
|
33
22
|
# Method arguments are the real values passed to (and received by) the function.
|
34
23
|
# @return [ReverseParameters::Arguments]
|
35
|
-
|
24
|
+
# @param [true, false] blocks_as_values: express block as variable vs a proc passed to the end of a method.
|
25
|
+
# def my_method(&block)
|
26
|
+
# end
|
27
|
+
# ReverseParameters.new(method(:my_method)).arguments(blocks_as_values: true).to_s
|
28
|
+
# #=> "block"
|
29
|
+
#
|
30
|
+
# # ReverseParameters.new(method(:my_method)).arguments.to_s
|
31
|
+
# #=> "&block"
|
32
|
+
def arguments(blocks_as_values: false)
|
36
33
|
Arguments.new(params, blocks_as_values: blocks_as_values)
|
37
34
|
end
|
38
35
|
|
39
36
|
private
|
40
|
-
attr_reader :params
|
37
|
+
attr_reader :params
|
41
38
|
|
42
39
|
class BaseCollection
|
43
40
|
include Enumerable
|
data/reverse_parameters.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reverse_parameters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dustin Zeisler
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
47
|
+
version: '3.4'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
54
|
+
version: '3.4'
|
55
55
|
description: 'Recreate ruby method signatures using ruby''s method to Proc creation
|
56
56
|
#method(:method_name).parameters. Use this to dynamically recreate method interfaces.'
|
57
57
|
email:
|
@@ -72,6 +72,9 @@ files:
|
|
72
72
|
- bin/console
|
73
73
|
- bin/setup
|
74
74
|
- lib/reverse_parameters.rb
|
75
|
+
- lib/reverse_parameters/core_ext.rb
|
76
|
+
- lib/reverse_parameters/core_ext/method.rb
|
77
|
+
- lib/reverse_parameters/core_ext/unbound_method.rb
|
75
78
|
- lib/reverse_parameters/version.rb
|
76
79
|
- reverse_parameters.gemspec
|
77
80
|
homepage: https://github.com/zeisler/reverse_parameters
|