yuyi 1.1.5 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f54fc12263a3eb78bf1b72db5bc3d08ff8509306
4
- data.tar.gz: 43ba00e4b501473bece5e67be9e5d5d33000d845
3
+ metadata.gz: 06030895fc322074fd3a878a5c80a08e97ea21fb
4
+ data.tar.gz: f624d1502202e155b7e74a0d10c182becf545358
5
5
  SHA512:
6
- metadata.gz: de8c5bf7eb451d5ea95428f38aef109b6be9036c07f185e710ccb52d5fbbfad4b329950ccf767a3655b1d88f4a6af56cf129b997f0f59f4192d9bb509f89221c
7
- data.tar.gz: a70065a9218a8a53ac88d66c5d85a70d60b09eb01c7f16466392ba89e903d9141621da10ef904450b5578546c66a67aa773127ab7449023523b90ba4d1d05139
6
+ metadata.gz: e72f7379391f73129aa928213e424c8107d55d3dab92a814af6ea19ab82af6e6f8f011876bfa55346deb09ed6a60dd6e9d57565bdb34e85f218cb0b562849c5f
7
+ data.tar.gz: 633457f35ad9e340b744c5bc18fc72484ad41e9f8f44eed06c26cc65860771b5c54bd1beda93231f73c77b26a753054c7b5b9880cf3f510e6bca7081aa36619b
data/.new CHANGED
@@ -16,4 +16,4 @@ tasks:
16
16
  - spec/**/*.rb
17
17
  project_name: Yuyi
18
18
  type: ruby
19
- version: 1.1.5
19
+ version: 1.1.6
data/README.md CHANGED
@@ -124,8 +124,6 @@ end
124
124
  ```
125
125
 
126
126
  ### TODO
127
- * vagrant plugins
128
- * Enforce required options
129
127
  * New roll generator (use new!)
130
128
  * show roll options on list
131
129
  * installation summary
data/lib/yuyi.rb CHANGED
@@ -8,7 +8,6 @@ require 'yuyi/source'
8
8
  require 'yuyi/ui'
9
9
 
10
10
  class Yuyi
11
- require 'yaml'
12
11
  extend Yuyi::Dsl
13
12
  extend Yuyi::Ui
14
13
 
data/lib/yuyi/cli.rb CHANGED
@@ -34,7 +34,6 @@ class Yuyi::Cli < Thor
34
34
  option :upgrade, :default => false, :aliases => '-u', :type => :boolean, :desc => 'Check for upgrades for rolls on the menu that are already installed'
35
35
  option :menu, :aliases => '-m', :desc => 'Path to your menu file'
36
36
  def start
37
- puts options.inspect
38
37
  # enable verbose mode if flag is passed
39
38
  Yuyi.verbose = options[:verbose]
40
39
  Yuyi.upgrade = options[:upgrade]
data/lib/yuyi/core.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems' # DEPRECATION: required for ruby 1.8.7
2
2
  require 'tsort'
3
+ require 'yaml'
3
4
 
4
5
  class Array
5
6
  def to_yaml_style
data/lib/yuyi/ui.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  module Yuyi::Ui
2
+ @@required = {}
3
+
2
4
  def header
3
5
  line_length = 50
4
6
  say
@@ -21,8 +23,7 @@ module Yuyi::Ui
21
23
  #
22
24
  def confirm_options
23
25
  confirm = false
24
- Yuyi::Menu.rolls.each do |name, roll|
25
-
26
+ Yuyi::Menu.rolls.values.each do |roll|
26
27
  unless roll.class.options.empty?
27
28
  present_options roll
28
29
  confirm = true
@@ -30,10 +31,35 @@ module Yuyi::Ui
30
31
  end
31
32
 
32
33
  if confirm
33
- say 'Your menu is being loaded from: ', :type => :warn, :newline => false
34
- say Yuyi::Menu.menu_path
35
- ask 'Make any changes you need to it, save it, and then press enter to continue.', :type => :warn do
36
- Yuyi::Menu.load_from_file
34
+ required_options_satisfied = false
35
+
36
+ until required_options_satisfied
37
+ say 'Your menu is being loaded from: ', :type => :warn, :newline => false
38
+ say Yuyi::Menu.menu_path
39
+ ask 'Make any neccessary changes to it, then press enter to continue.', :type => :warn do
40
+ Yuyi::Menu.load_from_file
41
+ end
42
+
43
+ # check that required options are satisfied
44
+ catch :required_options_satisfied do
45
+ @@required.each do |roll, required_options|
46
+ required_options.each do |required_option|
47
+ if Yuyi::Menu.options(roll)[required_option]
48
+ next
49
+ else
50
+ say 'Required option ', :type => :fail, :newline => false
51
+ say required_option, :newline => false
52
+ say ' for ', :type => :fail, :newline => false
53
+ say roll, :newline => false
54
+ say ' is not set', :type => :fail
55
+ say
56
+ throw :required_options_satisfied
57
+ end
58
+ end
59
+ end
60
+
61
+ required_options_satisfied = true
62
+ end
37
63
  end
38
64
  end
39
65
  end
@@ -63,14 +89,22 @@ module Yuyi::Ui
63
89
  say "#{roll.title} options", :color => :green
64
90
 
65
91
  roll.option_defs.each do |k, v|
66
- option_color = v[:required] ? :red : :default
92
+ if v[:required]
93
+ # add to required list
94
+ @@required[roll.file_name] ||= []
95
+ @@required[roll.file_name] << k
96
+
97
+ option_color = :red
98
+ else
99
+ option_color = :default
100
+ end
67
101
 
68
102
  # show option and description
69
103
  say "#{k.to_s.rjust(longest_option)}: ", :color => option_color, :newline => false
70
104
  say v[:description]
71
105
 
72
106
  # show default
73
- if v[:default]
107
+ if v[:default] && (!v[:default].respond_to?(:empty?) || (v[:default].respond_to?(:empty?) && !v[:default].empty?))
74
108
  say 'default: ', :indent => (longest_option + indent), :newline => false, :color => :yellow
75
109
  say v[:default]
76
110
  end
@@ -1,10 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Yuyi::Ui do
4
- describe '#present_options' do
5
- before do
6
- class UiTest; extend Yuyi::Ui; end
4
+ before do
5
+ class UiTest; extend Yuyi::Ui; end
6
+ Yuyi::Ui.class_var :required, {}
7
+ end
7
8
 
9
+ describe '.present_options' do
10
+ before do
8
11
  @output = ''
9
12
  allow(UiTest).to receive :say do |o, p|
10
13
  @output << (o || '')
@@ -19,6 +22,9 @@ describe Yuyi::Ui do
19
22
  :description => 'foo description',
20
23
  :example => '1.0',
21
24
  :default => '2.0'
25
+ },
26
+ :option_required_foo => {
27
+ :required => true
22
28
  }
23
29
  })
24
30
 
@@ -32,5 +38,37 @@ describe Yuyi::Ui do
32
38
  expect(@output).to include '1.0'
33
39
  expect(@output).to include '2.0'
34
40
  end
41
+
42
+ it 'should add to the required object' do
43
+ expect(Yuyi::Ui.class_var(:required)).to eq({ :present_options_roll => [:option_required_foo] })
44
+ end
45
+ end
46
+
47
+ describe '.confirm_options' do
48
+ before do
49
+ Yuyi::Ui.class_var :required, { :confirm_options_roll => [:option_foo]}
50
+
51
+ allow(UiTest).to receive(:present_options)
52
+ allow(UiTest).to receive(:say)
53
+ allow(UiTest).to receive(:ask)
54
+
55
+ class ConfirmOptionsRoll; end
56
+ @confirm_options_roll = ConfirmOptionsRoll.new
57
+ allow(ConfirmOptionsRoll).to receive(:options).and_return({ :option_foo => {}})
58
+
59
+ allow(Yuyi::Menu).to receive(:rolls).and_return({ :confirm_options_roll => @confirm_options_roll })
60
+ allow(Yuyi::Menu).to receive(:menu_path)
61
+ allow(Yuyi::Menu).to receive(:options).and_return({ :option_foo => nil }, { :option_foo => 'bar' })
62
+
63
+ UiTest.send :confirm_options
64
+ end
65
+
66
+ it 'should call present_options if there are rolls with options' do
67
+ expect(UiTest).to have_received(:present_options).with(@confirm_options_roll)
68
+ end
69
+
70
+ it 'should ask to reload the menu if required options arent satisfied' do
71
+ expect(UiTest).to have_received(:ask).twice
72
+ end
35
73
  end
36
74
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yuyi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Brewster
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-26 00:00:00.000000000 Z
11
+ date: 2014-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize