reverse_parameters 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -5
- data/lib/reverse_parameters.rb +5 -0
- data/lib/reverse_parameters/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbdaa436ad1d961969f0c4b2e68b41a4c675243a
|
4
|
+
data.tar.gz: ee4044dac199a904488ff433396cafbf498319a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b2987dba606dd3b323bd5940f1d56a1850e76c0bd50d6c0390dafea903ff7278d61b54433863381d9e8930141a52feb5e8f84b53b9fb6b31cae13c299eadc2e
|
7
|
+
data.tar.gz: aad7463471a424e34b8fa91d4bd40e3d48ee8f82d4f8f0dfa12b365f7050425c836434c8cd05ee8767365b66568b5599b114e86d5406aa443632d8339f791b6a
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/zeisler/reverse_parameters.svg)](https://travis-ci.org/zeisler/reverse_parameters)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/zeisler/active_mocker.png)](https://codeclimate.com/github/zeisler/reverse_parameters)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/reverse_parameters.svg)](http://badge.fury.io/rb/reverse_parameters)
|
5
6
|
|
6
7
|
Recreate ruby method signatures using ruby's method to Proc creation `#method(:method_name).parameters`. Use this to dynamically recreate method parameter interfaces.
|
7
8
|
|
@@ -28,17 +29,18 @@ require 'reverse_parameters'
|
|
28
29
|
|
29
30
|
def example_method(named_param:)
|
30
31
|
end
|
31
|
-
|
32
|
-
parameters = method(:example_method).parameters
|
33
|
-
#=> [[:keyreq, :named_param]]
|
34
32
|
|
35
33
|
# Method arguments are the real values passed to (and received by) the function.
|
36
|
-
ReverseParameters.
|
34
|
+
ReverseParameters.new(method(:example_method)).arguments.to_s
|
37
35
|
#=> "named_param: named_param"
|
38
36
|
|
39
37
|
# Method parameters are the names listed in the function definition.
|
40
|
-
ReverseParameters.
|
38
|
+
ReverseParameters.new(method(:example_method)).parameters.to_s
|
41
39
|
#=> "named_param:"
|
40
|
+
|
41
|
+
# Source Ruby API
|
42
|
+
method(:example_method).parameters
|
43
|
+
#=> [[:keyreq, :named_param]]
|
42
44
|
```
|
43
45
|
|
44
46
|
## Limitations
|
data/lib/reverse_parameters.rb
CHANGED
@@ -2,6 +2,7 @@ require "reverse_parameters/version"
|
|
2
2
|
|
3
3
|
class ReverseParameters
|
4
4
|
|
5
|
+
# @param input [Proc, Array]
|
5
6
|
def initialize(input)
|
6
7
|
if input.respond_to?(:to_proc)
|
7
8
|
@params = input.to_proc.parameters
|
@@ -13,11 +14,13 @@ class ReverseParameters
|
|
13
14
|
end
|
14
15
|
|
15
16
|
# Method parameters are the names listed in the function definition.
|
17
|
+
# @return [ReverseParameters::Parameters]
|
16
18
|
def parameters
|
17
19
|
Parameters.new(params)
|
18
20
|
end
|
19
21
|
|
20
22
|
# Method arguments are the real values passed to (and received by) the function.
|
23
|
+
# @return [ReverseParameters::Arguments]
|
21
24
|
def arguments
|
22
25
|
Arguments.new(params)
|
23
26
|
end
|
@@ -77,6 +80,8 @@ class ReverseParameters
|
|
77
80
|
name
|
78
81
|
when :rest
|
79
82
|
"*#{name}"
|
83
|
+
when :keyrest
|
84
|
+
"**#{name}"
|
80
85
|
when :opt
|
81
86
|
"#{name}=nil"
|
82
87
|
when :keyreq
|
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: 0.2.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: 2015-
|
11
|
+
date: 2015-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.2.5
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: Recreate ruby method signatures.
|