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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc400291392d1546d0296ebcd10e138871343f5b
4
- data.tar.gz: c97d099f20ded0fef91f52e660d7cb624a04d4b8
3
+ metadata.gz: fdf9c667689874d90a1054cc41df3113bcaafd35
4
+ data.tar.gz: 18f492d6d41851a951832e2ee1092090f4ae411f
5
5
  SHA512:
6
- metadata.gz: 9fdc4d1eb2bfafae669958d0ea2ce5f23a89a305404673e6eb67a2a0aa3163f9bffa818a7c7a499b385dc169acc0ca20433eddc385832ee90c5da384aaab1846
7
- data.tar.gz: cc6bb27ee263954aded6cba16a820dd587c2ab28a8868f4777ae1bccc2ee1aabda9c689a1e8300c51cc98426ab9240ef5659a64afd24a238df61088f681d3229
6
+ metadata.gz: ab20dbc01afe4bbb3f2f0063719be8ea0b556f73a459a6bf1a5159c9bef5efffa21b1e789d7d31947fc66318b314c6145afa8ab3dbd95d9dc419a25a24f13461
7
+ data.tar.gz: da12846f06e9da789f2da0ffb1f0b585cacdf6a359ec81dfe725f47ecd08a618b68f60106d0be7348702424327d5945561a9d4aceb68ace4abc8747b66b5e60e
data/CHANGELOG.md CHANGED
@@ -1,4 +1,12 @@
1
- ## Current 0.4.0
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
 
@@ -0,0 +1,6 @@
1
+ class Method
2
+ # @return [ReverseParameters]
3
+ def reverse_parameters
4
+ ReverseParameters.new(parameters)
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ class UnboundMethod
2
+ # @return [ReverseParameters]
3
+ def reverse_parameters
4
+ ReverseParameters.new(parameters)
5
+ end
6
+ end
@@ -0,0 +1,2 @@
1
+ require "reverse_parameters/core_ext/method"
2
+ require "reverse_parameters/core_ext/unbound_method"
@@ -1,3 +1,3 @@
1
1
  class ReverseParameters
2
- VERSION = "0.4.0"
2
+ VERSION = "1.0.0".freeze
3
3
  end
@@ -3,18 +3,7 @@ require "reverse_parameters/version"
3
3
  class ReverseParameters
4
4
 
5
5
  # @param [Proc, Array] input
6
- # @params [true, false] blocks_as_values defaults to false
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
- def arguments
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, :blocks_as_values
37
+ attr_reader :params
41
38
 
42
39
  class BaseCollection
43
40
  include Enumerable
@@ -23,5 +23,5 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.10"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "rspec", "~> 3.3"
26
+ spec.add_development_dependency "rspec", "~> 3.4"
27
27
  end
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.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-15 00:00:00.000000000 Z
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.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.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