has_keyword_argument 0.0.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 +7 -0
  2. data/lib/has_keyword_argument.rb +33 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 51f31e19f755f0a63c06e1d641582acd8a0172e9
4
+ data.tar.gz: 5f419479224f5abcdc9686512c8519e19fd00526
5
+ SHA512:
6
+ metadata.gz: 1504b3e3f8b73b4090b38d4fcdfbe5de9b7525fd9fbe3eaa58c256d526eefd899b00fc7235108a98cd5fe70cc73390cc926f1051ea3a1d4b0593a3c1cc0039ba
7
+ data.tar.gz: 3aa4257b907159c781c0acd1424ea8b688c601450aacd79282124957e7d08c128cfa6119cfeb5ce2b04c6a78e2353e4a238efb48b39891d3cfc716be4f3b25c6
@@ -0,0 +1,33 @@
1
+ def has_keyword_argument?(method:, keyword:)
2
+ unless method.is_a? Proc
3
+ raise ArgumentError, '`method` must be Proc'
4
+ end
5
+
6
+ unless keyword.class == String || keyword.class == Array
7
+ raise ArgumentError, '`keyword` must be String or Array'
8
+ end
9
+
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"
14
+ end
15
+ 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
+
24
+ #if keyword.is_a? Array
25
+ # output = flunk("missing keyword: #{keyword.join(': ')}")
26
+ #else
27
+ # output = flunk("missing keyword: #{keyword}")
28
+ #end
29
+ end
30
+
31
+ return output
32
+ end
33
+
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: has_keyword_argument
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Joel Eriksson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ''
14
+ email: joel.eriksson@protonmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/has_keyword_argument.rb
20
+ homepage: https://github.com/itggot-joel-eriksson/has_keyword_argument
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.5.1
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: A gem for use with MiniTest to check if certain keyword arguments are used
44
+ test_files: []