cli_miami 1.0.5.pre → 1.0.9.pre

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: 42418b61ff38c853438626c7bc70ad533ce728d7
4
- data.tar.gz: 8cc0c02b300bd52c9d15969edd95f88468717645
3
+ metadata.gz: e74cf731743ec201c0c4bac48b2b60644cd74b33
4
+ data.tar.gz: 5967a1bbf6ebcd77701f4cb05f2a1e4f13954b40
5
5
  SHA512:
6
- metadata.gz: 3df0997f3ba2a4e57859962b3024c3f488a04ffd59fccf3e8eca8d0a29cd5392aa70caac8240abcb7f6b503842e530449e9976a4ea38848b69c28c8902707ebc
7
- data.tar.gz: 2aba81627198c963ab0c46d44d2135cb0e7b492fec548927643d5d25251326ce500b87e4368e48e3018c38af5d9c26a2dffc16b559f4601408df380c9b088222
6
+ metadata.gz: 51b5d2c06581417dd46bf6dfdc14b40bf0090d601df88e40f43e6f5675fb5ec5fb546db8cbb1345f37ee06bc7e8e9cfbe53748b85b57a8df6eb1a44110aa9064
7
+ data.tar.gz: bfe0b344630ccb19f973aa73b8eeb53bd1deb1c2fd0ff2d7e660cadaea40e612a0ea3c11fac50ec6a9d12caaf69b4573c794a4af4a4b6ff122c0a0ba12a59607
data/i18n/en.yml CHANGED
@@ -1,4 +1,4 @@
1
- en:
1
+ en: &en
2
2
  cli_miami:
3
3
  # CliMiami core library strings
4
4
  core:
@@ -40,3 +40,9 @@ en:
40
40
  range:
41
41
  string:
42
42
  symbol:
43
+
44
+ # regional variations
45
+ en_gb:
46
+ <<: *en
47
+ en_us:
48
+ <<: *en
data/lib/cli_miami/ask.rb CHANGED
@@ -45,7 +45,7 @@ private
45
45
  def request_type options
46
46
  send("request_#{options[:type]}", options)
47
47
  rescue
48
- CliMiami::S.ay I18n.t('cli_miami.errors.type', options.merge(preset: :cli_miami_fail))
48
+ CliMiami::S.ay I18n.t('cli_miami.errors.type', type: options[:type]), options.merge(preset: :cli_miami_fail)
49
49
  end
50
50
 
51
51
  # for most types, a simple validation check is all that is needed
@@ -130,7 +130,9 @@ private
130
130
  # display options
131
131
  CliMiami::S.ay
132
132
  CliMiami::S.ay I18n.t('cli_miami.core.multiple_choice.prompt'), :cli_miami_instruction
133
- options[:choices].each_with_index do |li, i|
133
+ options[:choices].to_a.each_with_index do |li, i|
134
+ li = li[1] if li.is_a? Array
135
+
134
136
  # show already selected choices with a different color
135
137
  choice_text = "#{(i + 1).to_s.rjust(3)}: #{li}"
136
138
  choice_text_color = selected_choice_indexes.include?(i) ? :black : :cyan
@@ -159,11 +161,22 @@ private
159
161
  end
160
162
  end
161
163
 
164
+ # get selected choice values
165
+ selected_choices = selected_choice_indexes.map do |i|
166
+ options[:choices].to_a[i]
167
+ end
168
+
169
+ # convert associate array back to hash
170
+ if options[:choices].is_a? Hash
171
+ selected_choices = Hash[*selected_choices.flatten]
172
+ end
173
+
174
+ # show user their selected choices
162
175
  # update user
163
176
  CliMiami::S.ay
164
177
  CliMiami::S.ay I18n.t('cli_miami.core.multiple_choice.selected_choices'), :cli_miami_instruction_sub
165
- selected_choices = selected_choice_indexes.map{ |i| options[:choices][i] }
166
178
  selected_choices.each do |sc|
179
+ sc = sc[1] if sc.is_a? Array
167
180
  CliMiami::S.ay "• #{sc}", preset: :cli_miami_update, indent: 3
168
181
  end
169
182
  end
@@ -107,13 +107,13 @@ private
107
107
  i18n_string = keys.flatten.compact.each(&:to_s).join('.')
108
108
 
109
109
  # check if value exists, and translate it
110
- if I18n.exists? i18n_string
111
- # format description for i18n messages
112
- if options[:description]
113
- options[:description] = ' (' << options[:description] << ')'
114
- end
110
+ return unless I18n.exists? i18n_string
115
111
 
116
- I18n.t i18n_string, options
112
+ # format description for i18n messages
113
+ if options[:description]
114
+ options[:description] = ' (' << options[:description] << ')'
117
115
  end
116
+
117
+ I18n.t i18n_string, options
118
118
  end
119
119
  end
data/lib/cli_miami/say.rb CHANGED
@@ -67,13 +67,13 @@ private
67
67
 
68
68
  # Set foreground color
69
69
  def modify_text_color!
70
- if @options[:color]
71
- # if bright style is passed, use the bright color variation
72
- @text = if @options[:style].delete :bright
73
- @text.send "bright_#{@options[:color]}"
74
- else
75
- @text.send @options[:color]
76
- end
70
+ return unless @options[:color]
71
+
72
+ # if bright style is passed, use the bright color variation
73
+ @text = if @options[:style].delete :bright
74
+ @text.send "bright_#{@options[:color]}"
75
+ else
76
+ @text.send @options[:color]
77
77
  end
78
78
  end
79
79
 
@@ -111,14 +111,14 @@ private
111
111
  # validate the value is within the min and max values
112
112
  #
113
113
  def validate_length value, length, options
114
- unless (options[:min]..options[:max]).cover? length
115
- options[:value_length] = length
114
+ return if (options[:min]..options[:max]).cover? length
116
115
 
117
- # replace empty values with i18n `empty` string
118
- value = I18n.t('cli_miami.core.empty') if value.respond_to?(:empty?) && value.empty?
116
+ options[:value_length] = length
119
117
 
120
- raise CliMiami::Error.new(value, options, :length).message
121
- end
118
+ # replace empty values with i18n `empty` string
119
+ value = I18n.t('cli_miami.core.empty') if value.respond_to?(:empty?) && value.empty?
120
+
121
+ raise CliMiami::Error.new(value, options, :length).message
122
122
  end
123
123
 
124
124
  # validate that the value passes a regular expression
@@ -153,7 +153,7 @@ private
153
153
  validate_length float, float, options
154
154
  end
155
155
 
156
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
156
+ # rubocop:disable Metrics/AbcSize
157
157
  def validate_hash hash, options
158
158
  hash.deep_symbolize_keys!
159
159
 
@@ -162,18 +162,17 @@ private
162
162
  # return if no value options are set
163
163
  value_options = options[:value_options]
164
164
  return unless value_options
165
+ return unless value_options[:keys]
165
166
 
166
167
  # validate required keys are set
167
- if value_options[:keys]
168
- missing_keys = Set.new(value_options[:keys].map(&:to_sym)) - Set.new(hash.keys)
169
- value_options[:missing_values] = missing_keys.to_a.to_sentence
168
+ missing_keys = Set.new(value_options[:keys].map(&:to_sym)) - Set.new(hash.keys)
169
+ value_options[:missing_values] = missing_keys.to_a.to_sentence
170
170
 
171
- unless missing_keys.empty?
172
- raise CliMiami::Error.new(hash, options, :keys).message
173
- end
171
+ unless missing_keys.empty?
172
+ raise CliMiami::Error.new(hash, options, :keys).message
174
173
  end
175
174
  end
176
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
175
+ # rubocop:enable Metrics/AbcSize
177
176
 
178
177
  def validate_multiple_choice selections, options
179
178
  validate_length selections, selections.length, options
@@ -0,0 +1,3 @@
1
+ module CliMiami
2
+ VERSION = '1.0.9.pre'.freeze
3
+ end
data/lib/cli_miami.rb CHANGED
@@ -24,26 +24,25 @@ class String
24
24
  method_string = method.to_s.dup
25
25
 
26
26
  if method_string.slice! 'cli_miami_'
27
- preset = CliMiami.presets[method_string.to_sym]
27
+ method_symbol = method_string.to_sym
28
+ preset = CliMiami.presets[method_symbol] || {}
28
29
  options = preset.merge args[0] || {}
30
+
29
31
  CliMiami::S.ay self, options
30
32
  else
31
33
  super
32
34
  end
33
35
  end
36
+
37
+ def respond_to_missing? method, _args
38
+ method =~ /^cli_miami_/ || super
39
+ end
34
40
  end
35
41
 
36
42
  # i18n
37
43
  #
38
- # load yml locales included in the cli miami gem
39
- # [PATH TO GEMS]/cli_miami/i18n/en.yml
40
44
  I18n.load_path += Dir["#{File.dirname(__FILE__)}/../i18n/*.yml"]
41
- # load locale in current directory named `i18n.yml`
42
- # ./i18n.yml
43
- I18n.load_path += Dir['./i18n.yml']
44
- # load locales in the folder `i18n` in the current directory
45
- # ./i18n/en.yml
46
- I18n.load_path += Dir['./i18n/*.yml']
45
+ I18n.reload!
47
46
 
48
47
  # readline
49
48
  #
@@ -61,11 +60,6 @@ class FalseClass; include Boolean; end
61
60
  # create Cli Miami namespace and load library
62
61
  #
63
62
  module CliMiami
64
- require 'cli_miami/ask'
65
- require 'cli_miami/error'
66
- require 'cli_miami/say'
67
- require 'cli_miami/validation'
68
-
69
63
  BOOLEAN_TRUE_VALUES = %w(true t yes y).freeze
70
64
  BOOLEAN_FALSE_VALUES = %w(false f no n).freeze
71
65
 
@@ -202,4 +196,14 @@ module CliMiami
202
196
  options
203
197
  end
204
198
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
199
+
200
+ def self.version
201
+ CliMiami::VERSION
202
+ end
205
203
  end
204
+
205
+ require 'cli_miami/ask'
206
+ require 'cli_miami/error'
207
+ require 'cli_miami/say'
208
+ require 'cli_miami/validation'
209
+ require 'cli_miami/version'
@@ -55,6 +55,12 @@ describe CliMiami::A do
55
55
  end
56
56
 
57
57
  describe 'MULTIPLE_CHOICE' do
58
+ it 'should allow a hash of choices' do
59
+ allow($stdin).to receive(:gets).and_return '2', '1', ''
60
+ ask = CliMiami::A.sk @q, type: :multiple_choice, choices: { one: 'option 1', two: 'option 2', three: 'option 3' }
61
+ expect(ask.value).to eq(two: 'option 2', one: 'option 1')
62
+ end
63
+
58
64
  it 'should allow a user to remove selections' do
59
65
  allow($stdin).to receive(:gets).and_return '1', '2', '1', ''
60
66
  ask = CliMiami::A.sk @q, type: :multiple_choice, choices: ['option 1', 'option 2', 'option 3']
metadata CHANGED
@@ -1,175 +1,211 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cli_miami
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5.pre
4
+ version: 1.0.9.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Brewster
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-14 00:00:00.000000000 Z
11
+ date: 2016-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: 4.2.7.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: 4.2.7.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: i18n
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: '0.7'
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
- version: '0.7'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: term-ansicolor
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
- version: '1.3'
47
+ version: '0'
48
48
  type: :runtime
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: '1.3'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: coveralls
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
- version: '0.7'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
- version: '0.7'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
- version: '2.6'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
- version: '2.6'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: guard-bundler
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
- version: '2.1'
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
- version: '2.1'
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: guard-rubocop
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
- version: '1.2'
103
+ version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ~>
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
- version: '1.2'
110
+ version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: guard-rspec
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ~>
115
+ - - '>='
116
116
  - !ruby/object:Gem::Version
117
- version: '4.3'
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ~>
122
+ - - '>='
123
123
  - !ruby/object:Gem::Version
124
- version: '4.3'
124
+ version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: listen
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ~>
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 3.0.8
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
130
137
  - !ruby/object:Gem::Version
131
- version: 3.0.7
138
+ version: 3.0.8
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
132
143
  - - '>='
133
144
  - !ruby/object:Gem::Version
134
- version: 3.0.7
145
+ version: '0'
135
146
  type: :development
136
147
  prerelease: false
137
148
  version_requirements: !ruby/object:Gem::Requirement
138
149
  requirements:
139
- - - ~>
140
- - !ruby/object:Gem::Version
141
- version: 3.0.7
142
150
  - - '>='
143
151
  - !ruby/object:Gem::Version
144
- version: 3.0.7
152
+ version: '0'
145
153
  - !ruby/object:Gem::Dependency
146
- name: rspec
154
+ name: ruby_dep
147
155
  requirement: !ruby/object:Gem::Requirement
148
156
  requirements:
149
- - - ~>
157
+ - - '='
150
158
  - !ruby/object:Gem::Version
151
- version: '3.1'
159
+ version: 1.3.1
152
160
  type: :development
153
161
  prerelease: false
154
162
  version_requirements: !ruby/object:Gem::Requirement
155
163
  requirements:
156
- - - ~>
164
+ - - '='
157
165
  - !ruby/object:Gem::Version
158
- version: '3.1'
166
+ version: 1.3.1
167
+ - !ruby/object:Gem::Dependency
168
+ name: terminal-notifier
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
159
181
  - !ruby/object:Gem::Dependency
160
182
  name: terminal-notifier-guard
161
183
  requirement: !ruby/object:Gem::Requirement
162
184
  requirements:
163
- - - ~>
185
+ - - '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - '>='
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: yard
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - '>='
164
200
  - !ruby/object:Gem::Version
165
- version: '1.5'
201
+ version: '0'
166
202
  type: :development
167
203
  prerelease: false
168
204
  version_requirements: !ruby/object:Gem::Requirement
169
205
  requirements:
170
- - - ~>
206
+ - - '>='
171
207
  - !ruby/object:Gem::Version
172
- version: '1.5'
208
+ version: '0'
173
209
  description:
174
210
  email: brewster1134@gmail.com
175
211
  executables: []
@@ -184,6 +220,7 @@ files:
184
220
  - lib/cli_miami/global.rb
185
221
  - lib/cli_miami/say.rb
186
222
  - lib/cli_miami/validation.rb
223
+ - lib/cli_miami/version.rb
187
224
  - spec/fixtures/i18n.yml
188
225
  - spec/lib/cli_miami/ask_spec.rb
189
226
  - spec/lib/cli_miami/error_spec.rb