fedux_org-stdlib 0.6.39 → 0.6.40
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/fedux_org_stdlib/core_ext/hash/options.rb +43 -0
- data/lib/fedux_org_stdlib/version.rb +1 -1
- data/spec/core_ext/hash/options_spec.rb +51 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93d303a2d7b9dace940e87dcbb888ded268856f9
|
4
|
+
data.tar.gz: c9ac2d463177025b2e9e8117059e42600d662845
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b05ae79b60a72cfc8c41859c5f046aeba1958df6799c46b32a2918c5c5c109c2f4cdfd875d182d3b1d27d983a08ff3b7c4ad13f27952f2892fc5235a05c84f31
|
7
|
+
data.tar.gz: d000420eee51aa81424817a2f42bbad8ce92b2493d7d5d064a035246ea4cc141ff12362c52067d5d770189919d64df579dd168914462da062ce0665010815e75
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
class Hash
|
3
|
+
# Convert hash to command line options
|
4
|
+
#
|
5
|
+
# @example Convert true value
|
6
|
+
#
|
7
|
+
# hash = {
|
8
|
+
# opt1: true
|
9
|
+
# }
|
10
|
+
#
|
11
|
+
# hash.to_options
|
12
|
+
# # => [ '--opt1']
|
13
|
+
#
|
14
|
+
# @example Convert false value
|
15
|
+
#
|
16
|
+
# hash = {
|
17
|
+
# opt1: false
|
18
|
+
# }
|
19
|
+
#
|
20
|
+
# hash.to_options
|
21
|
+
# # => [ '--no-opt1']
|
22
|
+
#
|
23
|
+
# @example Convert other values
|
24
|
+
#
|
25
|
+
# hash = {
|
26
|
+
# opt1: 'string'
|
27
|
+
# }
|
28
|
+
#
|
29
|
+
# hash.to_options
|
30
|
+
# # => [ '--opt1', 'string']
|
31
|
+
def to_options
|
32
|
+
each_with_object([]) do |(key, value), a|
|
33
|
+
if value.is_a? TrueClass
|
34
|
+
a << "--#{key}"
|
35
|
+
elsif value.is_a? FalseClass
|
36
|
+
a << "--no-#{key}"
|
37
|
+
else
|
38
|
+
a << "--#{key}"
|
39
|
+
a << value.to_s
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'fedux_org_stdlib/core_ext/hash/options'
|
4
|
+
|
5
|
+
RSpec.describe '#to_options' do
|
6
|
+
it 'converts hash to array of command line options' do
|
7
|
+
hash = { }
|
8
|
+
|
9
|
+
expect(hash.to_options).to be_kind_of Array
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'converts true value' do
|
13
|
+
hash = {
|
14
|
+
opt1: true
|
15
|
+
}
|
16
|
+
|
17
|
+
expect(hash.to_options).to eq %w{ --opt1 }
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'converts false value' do
|
21
|
+
hash = {
|
22
|
+
opt1: false
|
23
|
+
}
|
24
|
+
|
25
|
+
expect(hash.to_options).to eq %w{ --no-opt1 }
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'converts integervalue' do
|
29
|
+
hash = {
|
30
|
+
opt1: 1
|
31
|
+
}
|
32
|
+
|
33
|
+
expect(hash.to_options).to eq %w{ --opt1 1 }
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'converts string value' do
|
37
|
+
hash = {
|
38
|
+
opt1: 'string'
|
39
|
+
}
|
40
|
+
|
41
|
+
expect(hash.to_options).to eq %w{ --opt1 string }
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'converts symbol value' do
|
45
|
+
hash = {
|
46
|
+
opt1: :string
|
47
|
+
}
|
48
|
+
|
49
|
+
expect(hash.to_options).to eq %w{ --opt1 string }
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fedux_org-stdlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.40
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Meyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/fedux_org_stdlib/command/run_command.rb
|
58
58
|
- lib/fedux_org_stdlib/command/which.rb
|
59
59
|
- lib/fedux_org_stdlib/core_ext/array.rb
|
60
|
+
- lib/fedux_org_stdlib/core_ext/hash/options.rb
|
60
61
|
- lib/fedux_org_stdlib/core_ext/string.rb
|
61
62
|
- lib/fedux_org_stdlib/environment.rb
|
62
63
|
- lib/fedux_org_stdlib/file_template.rb
|
@@ -137,6 +138,7 @@ files:
|
|
137
138
|
- spec/colors/html_color_spec.rb
|
138
139
|
- spec/command/run_command_spec.rb
|
139
140
|
- spec/command/which_spec.rb
|
141
|
+
- spec/core_ext/hash/options_spec.rb
|
140
142
|
- spec/environment_spec.rb
|
141
143
|
- spec/examples/models/class_based/forbidden_keyword.rb
|
142
144
|
- spec/examples/models/class_based/ignore/ignored.rb
|
@@ -205,6 +207,7 @@ test_files:
|
|
205
207
|
- spec/colors/html_color_spec.rb
|
206
208
|
- spec/command/run_command_spec.rb
|
207
209
|
- spec/command/which_spec.rb
|
210
|
+
- spec/core_ext/hash/options_spec.rb
|
208
211
|
- spec/environment_spec.rb
|
209
212
|
- spec/examples/models/class_based/forbidden_keyword.rb
|
210
213
|
- spec/examples/models/class_based/ignore/ignored.rb
|