has_keyword_argument 0.0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/has_keyword_argument.rb +14 -26
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51f31e19f755f0a63c06e1d641582acd8a0172e9
4
- data.tar.gz: 5f419479224f5abcdc9686512c8519e19fd00526
3
+ metadata.gz: f62bfeac10d810ec8e454f8e2c2206a70bd92beb
4
+ data.tar.gz: 4bba437a0b8d0e571facdd9e7d61498c1f753d1d
5
5
  SHA512:
6
- metadata.gz: 1504b3e3f8b73b4090b38d4fcdfbe5de9b7525fd9fbe3eaa58c256d526eefd899b00fc7235108a98cd5fe70cc73390cc926f1051ea3a1d4b0593a3c1cc0039ba
7
- data.tar.gz: 3aa4257b907159c781c0acd1424ea8b688c601450aacd79282124957e7d08c128cfa6119cfeb5ce2b04c6a78e2353e4a238efb48b39891d3cfc716be4f3b25c6
6
+ metadata.gz: 4c48e17f2887f6956d4d7a0ea54037b300baa92026d3029df612d25c6c16e6fbd70e306b9647a5d19aecf78ce0b4e9887eed5f9e062c026ef13ada4ba6bcecc2
7
+ data.tar.gz: 8224d484a0bd5d8ef8f21cb30883dfcd4a1bd03a003aec9f5062ac25f3b40fe60d3fe5496bca178d95a3fef6859e321af630f0656313de0864eb1f61654bf960
@@ -1,33 +1,21 @@
1
- def has_keyword_argument?(method:, keyword:)
2
- unless method.is_a? Proc
3
- raise ArgumentError, '`method` must be Proc'
4
- end
1
+ class Symbol
2
+ def has_keyword_argument? *keyword
3
+ keyword.uniq!
4
+ keyword.each_with_index do |keywd, i|
5
+ unless keywd.is_a? Symbol
6
+ raise ArgumentError, "Expected all `keyword´ to be Symbol, argument #{i} is #{keywd.class}"
7
+ end
8
+ end
5
9
 
6
- unless keyword.class == String || keyword.class == Array
7
- raise ArgumentError, '`keyword` must be String or Array'
8
- end
10
+ keyreq_params = []
9
11
 
10
- if keyword.is_a? Array
11
- keyword.each_with_index do |item, i|
12
- unless item.is_a? String
13
- raise ArgumentError, "`keyword` is Array but has #{item.class} at [#{i}]. Expected: String"
12
+ params = method(self).parameters
13
+ params.each do |param|
14
+ if param.first == :keyreq
15
+ keyreq_params << param.last
14
16
  end
15
17
  end
16
- end
17
-
18
- output = keyword
19
- begin
20
- method.call
21
- rescue ArgumentError => e
22
- output = e.message.split(':').first == 'missing keyword' ? e.message.split(':').last : e.message
23
18
 
24
- #if keyword.is_a? Array
25
- # output = flunk("missing keyword: #{keyword.join(': ')}")
26
- #else
27
- # output = flunk("missing keyword: #{keyword}")
28
- #end
19
+ keyreq_params.must_equal keyreq_params & keyword
29
20
  end
30
-
31
- return output
32
21
  end
33
-
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_keyword_argument
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Eriksson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-25 00:00:00.000000000 Z
11
+ date: 2016-10-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: ''
13
+ description: README.md
14
14
  email: joel.eriksson@protonmail.com
15
15
  executables: []
16
16
  extensions: []
@@ -40,5 +40,5 @@ rubyforge_project:
40
40
  rubygems_version: 2.5.1
41
41
  signing_key:
42
42
  specification_version: 4
43
- summary: A gem for use with MiniTest to check if certain keyword arguments are used
43
+ summary: A gem for use with Minitest to check if certain keyword arguments are used
44
44
  test_files: []