yuyi 1.0.3 → 1.0.4

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: 8667df310a7caf00f8607e5087c452a1ec32047b
4
- data.tar.gz: e9e2e237dcb9a5fe15f0c6b5395841d78f18b2cd
3
+ metadata.gz: 2d42b24d7281505899a99092cf0deffad8806cfe
4
+ data.tar.gz: e7f8ae082e4a25f178d530613624def9f28eedb0
5
5
  SHA512:
6
- metadata.gz: d085644d59271a419c13216437c879667d86f3701a13724e1aca6ea7231f84572881529a045758755be8be84190b6c3313638ab2e3ec3c9331b376c858322276
7
- data.tar.gz: 904a13f14634ba63338104d83ff881f10f76725c59f50d0f24191bbd5df2f7a2fc71428bfbd707c97fefb0bd39a68e99ec441302a908680d4340e63216828dd7
6
+ metadata.gz: e1a8ca7384b13712ec2b6f7929e3e6351ccf1f8e628c40729ee30e9a4746a489bc56bfad9bd396575b84290f2f8ee04751e404df7455b1a14c49c29d80767a34
7
+ data.tar.gz: 3ef10a04e372744cc27f2b950b636b666674a2be54d61e7acfe9e8d7ca84945f1159658a784ab7feee48f462aa26d8316606031a9f6868da4f525c3d8de3af42
data/.new CHANGED
@@ -16,4 +16,4 @@ tasks:
16
16
  - spec/**/*.rb
17
17
  project_name: Yuyi
18
18
  type: ruby
19
- version: 1.0.3
19
+ version: 1.0.4
data/lib/yuyi/menu.rb CHANGED
@@ -40,13 +40,13 @@ class Yuyi::Menu
40
40
  end
41
41
 
42
42
  # Attempt to load a menu from a file path
43
- # defaults to previously stored @path value
44
43
  #
45
44
  def self.load_from_file path = path
46
45
  menu = begin
47
46
  File.open(File.expand_path(path))
48
47
  rescue
49
- Yuyi.run "curl -sS #{path}"
48
+ response = Yuyi.run "curl -sS #{path}"
49
+ $?.success? ? response : nil
50
50
  end
51
51
 
52
52
  @object = begin
@@ -2,194 +2,207 @@ require 'spec_helper'
2
2
 
3
3
  describe Yuyi::Menu do
4
4
  before do
5
- @menu = Yuyi::Menu.new 'spec/fixtures/menu.yaml'
5
+ Yuyi::Menu.send :class_variable_set, :'@@instance', nil
6
+ Yuyi::Menu.send :instance_variable_set, :'@object', nil
6
7
  end
7
8
 
8
- describe '.load_from_file' do
9
- context 'with a local file' do
9
+ describe '#initialize' do
10
+ context 'with a valid path' do
10
11
  before do
11
- Yuyi::Menu.load_from_file 'spec/fixtures/menu2.yaml'
12
- end
13
-
14
- it 'should update the menu object' do
15
- expect(@menu.object[:rolls][:foo_roll]).to eq({ :bar => 'foo' })
12
+ Yuyi::Menu.new 'spec/fixtures/menu.yaml'
16
13
  end
17
- end
18
14
 
19
- context 'with a remote file' do
20
- before do
21
- allow(Yuyi).to receive(:run).and_return({ :foo => 'bar' }.to_yaml)
22
- Yuyi::Menu.load_from_file 'file://menu.yaml'
15
+ it 'should set the path var' do
16
+ expect(Yuyi::Menu.path).to eq 'spec/fixtures/menu.yaml'
23
17
  end
24
18
 
25
- after do
26
- allow(Yuyi).to receive(:run).and_call_original
19
+ it 'should set the instance on the menu class' do
20
+ expect(Yuyi::Menu.instance).to eq Yuyi::Menu.instance
27
21
  end
28
22
 
29
- it 'should update the menu object' do
30
- expect(@menu.object[:foo]).to eq 'bar'
23
+ it 'should set the object var' do
24
+ expect(Yuyi::Menu.object[:sources][0]).to eq({ :local => 'spec/fixtures/roll_dir' })
25
+ expect(Yuyi::Menu.object[:sources][1]).to eq({ :yuyi => 'spec/fixtures/roll_zip.zip' })
26
+ expect(Yuyi::Menu.object[:rolls][:foo_roll]).to eq({ :foo => 'bar' })
31
27
  end
32
28
  end
33
- end
34
-
35
- describe '.add_roll' do
36
- before do
37
- class MenuAddRollRoll; end
38
- Yuyi::Menu.add_roll :menu_add_roll_roll, MenuAddRollRoll
39
- end
40
-
41
- it 'should add a roll instance' do
42
- expect(Yuyi::Menu.instance_var(:rolls)[:menu_add_roll_roll]).to be_a MenuAddRollRoll
43
- end
44
- end
45
-
46
- describe '#initialize' do
47
- it 'should set the path var' do
48
- expect(@menu.var(:path)).to eq 'spec/fixtures/menu.yaml'
49
- end
50
-
51
- it 'should set the instance on the menu class' do
52
- expect(Yuyi::Menu.instance).to eq @menu
53
- end
54
-
55
- it 'should set the object var' do
56
- expect(Yuyi::Menu.instance_var(:object)[:sources][0]).to eq({ :local => 'spec/fixtures/roll_dir' })
57
- expect(Yuyi::Menu.instance_var(:object)[:sources][1]).to eq({ :yuyi => 'spec/fixtures/roll_zip.zip' })
58
- expect(Yuyi::Menu.instance_var(:object)[:rolls][:foo_roll]).to eq({ :foo => 'bar' })
59
- end
60
29
 
61
30
  context 'with an invalid path' do
62
31
  before do
63
- @menu = Yuyi::Menu.new 'foo'
32
+ Yuyi::Menu.new 'foo'
64
33
  end
65
34
 
66
- it 'should not update menu state' do
67
- expect(Yuyi::Menu).to_not eq @menu
35
+ it 'should have a nil instance' do
36
+ expect(Yuyi::Menu.instance).to be_nil
68
37
  end
69
38
 
70
39
  it 'should have a nil object' do
71
- expect(Yuyi::Menu.instance_var(:object)).to be_nil
40
+ expect(Yuyi::Menu.object).to be_nil
72
41
  end
73
42
  end
74
43
  end
75
44
 
76
- describe '#set_sources' do
45
+ context 'when valid menu already initialized' do
77
46
  before do
78
- Yuyi::Menu.instance_var :object, { :sources => [{ :foo_source => 'foo/path' }]}
47
+ Yuyi::Menu.new 'spec/fixtures/menu.yaml'
48
+ end
79
49
 
80
- class FooSource; end
81
- allow(Yuyi::Source).to receive(:new).and_return FooSource
50
+ describe '.load_from_file' do
51
+ context 'with a local file' do
52
+ before do
53
+ Yuyi::Menu.load_from_file 'spec/fixtures/menu2.yaml'
54
+ end
82
55
 
83
- @menu.send :set_sources
84
- end
56
+ it 'should update the menu object' do
57
+ expect(Yuyi::Menu.instance.object[:rolls][:foo_roll]).to eq({ :bar => 'foo' })
58
+ end
59
+ end
85
60
 
86
- it 'should set the sources var' do
87
- expect(@menu.var(:sources).size).to eq(1)
88
- expect(@menu.var(:sources)[0]).to eq FooSource
89
- end
90
- end
61
+ context 'with a remote file' do
62
+ before do
63
+ allow(Yuyi).to receive(:run).and_return({ :foo => 'bar' }.to_yaml)
64
+ Yuyi::Menu.load_from_file 'file://menu.yaml'
65
+ end
91
66
 
92
- describe '#find_roll' do
93
- before do
94
- allow(@menu).to receive :require_roll
67
+ after do
68
+ allow(Yuyi).to receive(:run).and_call_original
69
+ end
70
+
71
+ it 'should update the menu object' do
72
+ expect(Yuyi::Menu.instance.object[:foo]).to eq 'bar'
73
+ end
74
+ end
95
75
  end
96
76
 
97
- context 'when a source is specified' do
77
+ describe '.add_roll' do
98
78
  before do
99
- @menu.send :find_roll, :foo_roll, { :source => 'foo_source' }
79
+ class MenuAddRollRoll; end
80
+ Yuyi::Menu.add_roll :menu_add_roll_roll, MenuAddRollRoll
100
81
  end
101
82
 
102
- it 'should require the specific roll' do
103
- expect(@menu).to have_received(:require_roll).once.with(:foo_roll, 'foo_source/foo_roll')
83
+ it 'should add a roll instance' do
84
+ expect(Yuyi::Menu.instance_var(:rolls)[:menu_add_roll_roll]).to be_a MenuAddRollRoll
104
85
  end
105
86
  end
106
87
 
107
- context 'when no source is specified' do
88
+ describe '#set_sources' do
108
89
  before do
109
- class TestSourceA; end
110
- class TestSourceB; end
111
- allow(TestSourceA).to receive(:available_rolls).and_return({ :foo_roll => 'foo_roll' })
112
- allow(TestSourceB).to receive(:available_rolls).and_return({ :bar_roll => 'bar_roll' })
90
+ Yuyi::Menu.instance_var :object, { :sources => [{ :foo_source => 'foo/path' }]}
91
+
92
+ class FooSource; end
93
+ allow(Yuyi::Source).to receive(:new).and_return FooSource
113
94
 
114
- @menu.var :sources, [TestSourceA, TestSourceB]
95
+ Yuyi::Menu.instance.send :set_sources
115
96
  end
116
97
 
117
- it 'should require the first roll found' do
118
- expect(@menu).to receive(:require_roll).once.with(:bar_roll, 'bar_roll')
119
- @menu.send :find_roll, :bar_roll
98
+ it 'should set the sources var' do
99
+ expect(Yuyi::Menu.instance.var(:sources).size).to eq(1)
100
+ expect(Yuyi::Menu.instance.var(:sources)[0]).to eq FooSource
120
101
  end
121
102
  end
122
103
 
123
- context 'when no roll is found' do
104
+ describe '#find_roll' do
124
105
  before do
125
- class TestSource; end
126
- allow(TestSource).to receive(:available_rolls).and_return({})
106
+ allow(Yuyi::Menu.instance).to receive :require_roll
107
+ end
108
+
109
+ context 'when a source is specified' do
110
+ before do
111
+ Yuyi::Menu.instance.send :find_roll, :foo_roll, { :source => 'foo_source' }
112
+ end
127
113
 
128
- @menu.var :sources, [TestSource]
114
+ it 'should require the specific roll' do
115
+ expect(Yuyi::Menu.instance).to have_received(:require_roll).once.with(:foo_roll, 'foo_source/foo_roll')
116
+ end
129
117
  end
130
118
 
131
- it 'should not attempt to require a roll' do
132
- expect(@menu).to_not receive(:require_roll)
133
- @menu.send :find_roll, :no_roll
119
+ context 'when no source is specified' do
120
+ before do
121
+ class TestSourceA; end
122
+ class TestSourceB; end
123
+ allow(TestSourceA).to receive(:available_rolls).and_return({ :foo_roll => 'foo_roll' })
124
+ allow(TestSourceB).to receive(:available_rolls).and_return({ :bar_roll => 'bar_roll' })
125
+
126
+ Yuyi::Menu.instance.var :sources, [TestSourceA, TestSourceB]
127
+ end
128
+
129
+ it 'should require the first roll found' do
130
+ expect(Yuyi::Menu.instance).to receive(:require_roll).once.with(:bar_roll, 'bar_roll')
131
+ Yuyi::Menu.instance.send :find_roll, :bar_roll
132
+ end
134
133
  end
135
- end
136
- end
137
134
 
138
- describe '#on_the_menu?' do
139
- before do
140
- allow(@menu).to receive(:object).and_return({ :rolls => { :foo => nil }})
141
- end
135
+ context 'when no roll is found' do
136
+ before do
137
+ class TestSource; end
138
+ allow(TestSource).to receive(:available_rolls).and_return({})
142
139
 
143
- it 'should return true if on the menu' do
144
- expect(@menu.on_the_menu?(:foo)).to be true
140
+ Yuyi::Menu.instance.var :sources, [TestSource]
141
+ end
142
+
143
+ it 'should not attempt to require a roll' do
144
+ expect(Yuyi::Menu.instance).to_not receive(:require_roll)
145
+ Yuyi::Menu.instance.send :find_roll, :no_roll
146
+ end
147
+ end
145
148
  end
146
- end
147
149
 
148
- describe '#sorted_rolls' do
149
- before do
150
- class DependencyRoll
151
- def dependencies; ['foo', 'bar']; end
150
+ describe '#on_the_menu?' do
151
+ before do
152
+ allow(Yuyi::Menu.instance).to receive(:object).and_return({ :rolls => { :foo => nil }})
152
153
  end
153
- class EmptyDependencyRoll
154
- def dependencies; []; end
154
+
155
+ it 'should return true if on the menu' do
156
+ expect(Yuyi::Menu.instance.on_the_menu?(:foo)).to be true
155
157
  end
156
- allow(@menu).to receive(:rolls).and_return({ :dependency_roll => DependencyRoll.new, :foo => EmptyDependencyRoll.new, :bar => EmptyDependencyRoll.new })
157
158
  end
158
159
 
159
- it 'should add the roll to the class var' do
160
- expect(@menu.send(:sorted_rolls).sort_by { |sym| sym.to_s }).to eq([:bar, :dependency_roll, :foo])
161
- end
162
- end
160
+ describe '#sorted_rolls' do
161
+ before do
162
+ class DependencyRoll
163
+ def dependencies; ['foo', 'bar']; end
164
+ end
165
+ class EmptyDependencyRoll
166
+ def dependencies; []; end
167
+ end
168
+ allow(Yuyi::Menu.instance).to receive(:rolls).and_return({ :dependency_roll => DependencyRoll.new, :foo => EmptyDependencyRoll.new, :bar => EmptyDependencyRoll.new })
169
+ end
163
170
 
164
- describe '#order_rolls' do
165
- before do
166
- class MenuOrderRollsOne; end
167
- class MenuOrderRollsTwo; end
168
- allow(MenuOrderRollsOne).to receive :appetizers
169
- allow(MenuOrderRollsTwo).to receive :appetizers
170
- allow(MenuOrderRollsOne).to receive :entree
171
- allow(MenuOrderRollsTwo).to receive :entree
172
- allow(MenuOrderRollsOne).to receive :dessert
173
- allow(MenuOrderRollsTwo).to receive :dessert
174
-
175
- allow(@menu).to receive(:sorted_rolls).and_return([:menu_order_rolls_one, :menu_order_rolls_two])
176
- allow(@menu).to receive(:rolls).and_return({ :menu_order_rolls_one => MenuOrderRollsOne, :menu_order_rolls_two => MenuOrderRollsTwo })
177
-
178
- @menu.send :order_rolls
171
+ it 'should add the roll to the class var' do
172
+ expect(Yuyi::Menu.instance.send(:sorted_rolls).sort_by { |sym| sym.to_s }).to eq([:bar, :dependency_roll, :foo])
173
+ end
179
174
  end
180
175
 
181
- after do
182
- allow(@menu).to receive(:sorted_rolls).and_call_original
183
- allow(@menu).to receive(:rolls).and_call_original
184
- end
176
+ describe '#order_rolls' do
177
+ before do
178
+ class MenuOrderRollsOne; end
179
+ class MenuOrderRollsTwo; end
180
+ allow(MenuOrderRollsOne).to receive :appetizers
181
+ allow(MenuOrderRollsTwo).to receive :appetizers
182
+ allow(MenuOrderRollsOne).to receive :entree
183
+ allow(MenuOrderRollsTwo).to receive :entree
184
+ allow(MenuOrderRollsOne).to receive :dessert
185
+ allow(MenuOrderRollsTwo).to receive :dessert
185
186
 
186
- it 'should initialize a roll with the roll options' do
187
- expect(MenuOrderRollsOne).to have_received(:appetizers).ordered
188
- expect(MenuOrderRollsTwo).to have_received(:appetizers).ordered
189
- expect(MenuOrderRollsOne).to have_received(:entree).ordered
190
- expect(MenuOrderRollsTwo).to have_received(:entree).ordered
191
- expect(MenuOrderRollsOne).to have_received(:dessert).ordered
192
- expect(MenuOrderRollsTwo).to have_received(:dessert).ordered
187
+ allow(Yuyi::Menu.instance).to receive(:sorted_rolls).and_return([:menu_order_rolls_one, :menu_order_rolls_two])
188
+ allow(Yuyi::Menu.instance).to receive(:rolls).and_return({ :menu_order_rolls_one => MenuOrderRollsOne, :menu_order_rolls_two => MenuOrderRollsTwo })
189
+
190
+ Yuyi::Menu.instance.send :order_rolls
191
+ end
192
+
193
+ after do
194
+ allow(Yuyi::Menu.instance).to receive(:sorted_rolls).and_call_original
195
+ allow(Yuyi::Menu.instance).to receive(:rolls).and_call_original
196
+ end
197
+
198
+ it 'should initialize a roll with the roll options' do
199
+ expect(MenuOrderRollsOne).to have_received(:appetizers).ordered
200
+ expect(MenuOrderRollsTwo).to have_received(:appetizers).ordered
201
+ expect(MenuOrderRollsOne).to have_received(:entree).ordered
202
+ expect(MenuOrderRollsTwo).to have_received(:entree).ordered
203
+ expect(MenuOrderRollsOne).to have_received(:dessert).ordered
204
+ expect(MenuOrderRollsTwo).to have_received(:dessert).ordered
205
+ end
193
206
  end
194
207
  end
195
208
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yuyi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Brewster