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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f50e5da204182fa2c7095a368e0eb4676335089
4
- data.tar.gz: fe37bae8c22ce61576def828beb229a09ecafe71
3
+ metadata.gz: 93d303a2d7b9dace940e87dcbb888ded268856f9
4
+ data.tar.gz: c9ac2d463177025b2e9e8117059e42600d662845
5
5
  SHA512:
6
- metadata.gz: 96d3891878ec9f7c5a38d5d9f53e714c1f20468d20da23f8f5b01651fb52f52f730f81461664a3a6f976be1880f65980a0bce45428517b01c9c11dc809096925
7
- data.tar.gz: d63b85f1b7d7fb577e677e6ef02aec925a880bf381946b91455d54f6ccb4a000b605a37dc399d1d81dc3c95a9f6f8adc8afd3544b97b5ed498e2438853e34efc
6
+ metadata.gz: b05ae79b60a72cfc8c41859c5f046aeba1958df6799c46b32a2918c5c5c109c2f4cdfd875d182d3b1d27d983a08ff3b7c4ad13f27952f2892fc5235a05c84f31
7
+ data.tar.gz: d000420eee51aa81424817a2f42bbad8ce92b2493d7d5d064a035246ea4cc141ff12362c52067d5d770189919d64df579dd168914462da062ce0665010815e75
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fedux_org-stdlib (0.6.38)
4
+ fedux_org-stdlib (0.6.39)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -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
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  # FeduxOrgStdlib
3
3
  module FeduxOrgStdlib
4
- VERSION = '0.6.39'
4
+ VERSION = '0.6.40'
5
5
  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.39
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-05 00:00:00.000000000 Z
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