yuyi 0.0.8 → 1.0.0

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: 18669c8bff30c75da353c6ead6b04f6ac8851584
4
- data.tar.gz: a557a329c99d67a8553eb575a580e8a0f7a57c5e
3
+ metadata.gz: c6cca5d2ab1d4af450cfb97cdebae51e7fd270a9
4
+ data.tar.gz: 34729bb8572ea41c40c9ae276f536aaebf20e86a
5
5
  SHA512:
6
- metadata.gz: 374c7d7a1f7499774310e55f717f3eac0ab69f1ab644657f88522a078422e0edd2c3417f3eccf489f556c6e49ada808820b04448ac5bfce31f6fd0e1cead4ffd
7
- data.tar.gz: eeff542c9a3914ea9d2df428caaec4d7ee43f96764cb13fba665c107ef53dba63ea2794c8e8998d73b7e8d2e8f523c0d1355820ec90f0196e73eca89f400ba8d
6
+ metadata.gz: 4b8e5fe1d299b56c7b2e7b3237babebad22de7de6e5c86e1c0cd3ba99d93ab5709e79e48c66fd232774a639f8fb0ea7327940be8327c731bb499ce48b80c5197
7
+ data.tar.gz: c1d580a528433bccccbcd505c2c26f372873c76e8c5adb8d8d03ade2426c0da7303e9ca9fb5537ced87d0c76f179764d2f627ed220b415466884969b9c8fda99
data/.new CHANGED
@@ -16,4 +16,4 @@ tasks:
16
16
  - spec/**/*.rb
17
17
  project_name: Yuyi
18
18
  type: ruby
19
- version: 0.0.8
19
+ version: 1.0.0
@@ -14,7 +14,7 @@ def download_app
14
14
  end
15
15
 
16
16
  def install
17
- system "ruby #{install_dir}/bin/yuyi -V"
17
+ system "ruby #{install_dir}/bin/yuyi"
18
18
  end
19
19
 
20
20
  def cleanup
@@ -107,7 +107,7 @@ module Yuyi::Cli
107
107
  end.rstrip
108
108
 
109
109
  say
110
- yield output
110
+ yield output if block
111
111
  end
112
112
 
113
113
  # Run a command and output formatting success/errors
@@ -133,6 +133,8 @@ module Yuyi::Cli
133
133
  # Write several lines to to an existing file
134
134
  #
135
135
  def write_to_file file, *text
136
+ text.flatten!
137
+
136
138
  File.open(File.expand_path(file), 'a+') do |file|
137
139
  full_text = (text * "\n") + "\n"
138
140
 
@@ -145,6 +147,8 @@ module Yuyi::Cli
145
147
  # Delete specific lines from an existing file
146
148
  #
147
149
  def delete_from_file file, *text
150
+ text.flatten!
151
+
148
152
  # get file text
149
153
  new_text = File.read(File.expand_path(file))
150
154
 
@@ -248,8 +252,14 @@ private
248
252
  say 'NOTE: This is passed directly to sudo and is not saved.'
249
253
  say ' This will ensure all your installs run unsupervised.'
250
254
 
251
- # clear sudo timestamp & run any command as admin to force a password prompt
252
- system 'sudo -k; sudo echo >> /dev/null 2>&1'
255
+ # keep the sudo timestamp fresh
256
+ Thread::new do
257
+ loop do
258
+ sleep 1.minute
259
+ `sudo -v`
260
+ end
261
+ end
262
+
253
263
  say
254
264
  end
255
265
 
@@ -267,8 +277,10 @@ private
267
277
  say "#{k.to_s.rjust(longest_option)}: ", :color => option_color, :newline => false
268
278
  say v[:description]
269
279
  say (' ' * (longest_option + indent)), :newline => false
270
- say 'default: ', :color => 36, :newline => false
271
- say v[:default]
280
+ if v[:default]
281
+ say 'default: ', :color => 36, :newline => false
282
+ say v[:default]
283
+ end
272
284
  end
273
285
 
274
286
  if examples
@@ -288,7 +300,7 @@ private
288
300
 
289
301
  say
290
302
  say 'Example', :color => 33, :indent => example_indent, :newline => false
291
- say examples_hash.deep_stringify_keys!.to_yaml.sub("--- ", '').gsub(/\n(\s*)/, "\n\\1#{' ' * example_indent}")
303
+ say examples_hash.deep_stringify_keys!.to_yaml.sub('---', '').gsub(/\n(\s*)/, "\n\\1#{' ' * example_indent}")
292
304
  end
293
305
  end
294
306
 
@@ -94,19 +94,41 @@ class Yuyi::Menu
94
94
  # Initialize all the rolls in order
95
95
  #
96
96
  def order_rolls
97
+ header_length = 80
97
98
  all_rolls = sorted_rolls
98
99
 
99
- # run all preinstalls first
100
+
101
+ # pre installs
102
+ #
103
+ Yuyi.say '=' * header_length, :color => 35
104
+ Yuyi.say 'APPETIZERS', :color => 35, :justify => :center, :padding => header_length
105
+ Yuyi.say 'Pre Install Tasks', :justify => :center, :padding => header_length
106
+ Yuyi.say
107
+
100
108
  all_rolls.each do |file_name|
101
109
  rolls[file_name].appetizers
102
110
  end
103
111
 
104
- # then run all installs
112
+
113
+ # main installs
114
+ #
115
+ Yuyi.say '=' * header_length, :color => 36
116
+ Yuyi.say 'ENTREES', :color => 36, :justify => :center, :padding => header_length
117
+ Yuyi.say 'Main Install Tasks', :justify => :center, :padding => header_length
118
+ Yuyi.say
119
+
105
120
  all_rolls.each do |file_name|
106
121
  rolls[file_name].entree
107
122
  end
108
123
 
109
- # then post installs last
124
+
125
+ # post installs
126
+ #
127
+ Yuyi.say '=' * header_length, :color => 35
128
+ Yuyi.say 'DESSERT', :color => 35, :justify => :center, :padding => header_length
129
+ Yuyi.say 'Post Install Tasks', :justify => :center, :padding => header_length
130
+ Yuyi.say
131
+
110
132
  all_rolls.each do |file_name|
111
133
  rolls[file_name].dessert
112
134
  end
@@ -139,6 +161,19 @@ class Yuyi::Menu
139
161
  Yuyi.say
140
162
  end
141
163
 
164
+ # Find the best roll in the source to be added
165
+ #
166
+ def find_roll_model name, path
167
+ # look through the sources for the first roll model that matches.
168
+ # sources are listed in the menu in order of priority
169
+ sources.each do |source|
170
+ if path = source.roll_models[name]
171
+ require path
172
+ return
173
+ end
174
+ end
175
+ end
176
+
142
177
  private
143
178
 
144
179
  def initialize path
@@ -148,9 +183,27 @@ private
148
183
  @@instance = self
149
184
 
150
185
  set_sources
186
+ set_roll_models
151
187
  set_rolls
152
188
  end
153
189
 
190
+ # Create all rolls on the menu
191
+ #
192
+ def set_roll_models
193
+ object[:roll_models] = {}
194
+
195
+ # collect all roll models from all sources
196
+ sources.each do |source|
197
+ source.roll_models.each do |name, path|
198
+ object[:roll_models][name] = path
199
+ end
200
+ end
201
+
202
+ object[:roll_models].each do |name, path|
203
+ find_roll_model name, path
204
+ end
205
+ end
206
+
154
207
  # Create all rolls on the menu
155
208
  #
156
209
  def set_rolls
@@ -13,27 +13,51 @@ class Yuyi::Roll
13
13
  end
14
14
 
15
15
  def self.pre_install &block
16
- @pre_install ||= block
16
+ if block
17
+ @pre_install = block
18
+ else
19
+ @pre_install
20
+ end
17
21
  end
18
22
 
19
23
  def self.install &block
20
- @install ||= block
24
+ if block
25
+ @install = block
26
+ else
27
+ @install
28
+ end
21
29
  end
22
30
 
23
31
  def self.post_install &block
24
- @post_install ||= block
32
+ if block
33
+ @post_install = block
34
+ else
35
+ @post_install
36
+ end
25
37
  end
26
38
 
27
39
  def self.uninstall &block
28
- @uninstall ||= block
40
+ if block
41
+ @uninstall = block
42
+ else
43
+ @uninstall
44
+ end
29
45
  end
30
46
 
31
47
  def self.upgrade &block
32
- @upgrade ||= block
48
+ if block
49
+ @upgrade = block
50
+ else
51
+ @upgrade
52
+ end
33
53
  end
34
54
 
35
55
  def self.installed? &block
36
- @installed ||= block
56
+ if block
57
+ @installed = block
58
+ else
59
+ @installed
60
+ end
37
61
  end
38
62
 
39
63
  def self.dependencies *dependencies
@@ -117,15 +141,29 @@ private
117
141
  # Add to global collection of rolls
118
142
  #
119
143
  def self.inherited klass
120
- # convert class name to a human readble title-cased string
121
- klass.title klass.to_s.gsub(/(?=[A-Z])/, ' ').strip
144
+ return if klass.to_s.include? 'RollModel'
145
+
146
+ add_roll klass, caller
147
+ end
148
+
149
+ def self.add_roll klass, caller
150
+ # convert class name to a title string
151
+ klass.title class_to_title klass
122
152
 
123
- # convert absolute path to a file name symbol
124
- klass.file_name caller.first[/[a-z_]+?(?=\.rb)/].to_sym
153
+ # convert caller to a file name symbol
154
+ klass.file_name caller_to_file_name caller
125
155
 
126
156
  Yuyi::Menu.add_roll klass.file_name, klass
127
157
  end
128
158
 
159
+ def self.class_to_title klass
160
+ klass.to_s.match(/[^:]+$/)[0].gsub(/(?=[A-Z])/, ' ').strip
161
+ end
162
+
163
+ def self.caller_to_file_name caller
164
+ caller.first[/[a-z_]+?(?=\.rb)/].to_sym
165
+ end
166
+
129
167
  def self.require_dependencies
130
168
  @dependencies.each do |roll|
131
169
  unless Yuyi::Menu.on_the_menu? roll
@@ -135,6 +173,7 @@ private
135
173
  end
136
174
 
137
175
  def pre_install
176
+ return unless self.class.pre_install
138
177
  instance_eval(&self.class.pre_install)
139
178
  end
140
179
 
@@ -143,6 +182,7 @@ private
143
182
  end
144
183
 
145
184
  def post_install
185
+ return unless self.class.post_install
146
186
  instance_eval(&self.class.post_install)
147
187
  end
148
188
 
@@ -160,6 +200,7 @@ private
160
200
 
161
201
  # Helpers for Yuyi Cli methods
162
202
  def say *args; Yuyi.say *args; end
203
+ def ask *args; Yuyi.ask *args; end
163
204
  def run *args; Yuyi.run *args; end
164
205
  def command? *args; Yuyi.command? *args; end
165
206
  def osx_version; Yuyi.osx_version; end
@@ -6,6 +6,7 @@ class Yuyi::Source
6
6
  ROLL_FILE_GLOB = '**/*.rb'
7
7
 
8
8
  def available_rolls; @available_rolls end
9
+ def roll_models; @roll_models end
9
10
 
10
11
  private
11
12
 
@@ -16,12 +17,13 @@ private
16
17
 
17
18
  def initialize name, path
18
19
  @available_rolls = {}
20
+ @roll_models = {}
19
21
  @name = name
20
22
  @path = path
21
23
 
22
24
  create_tmp_dir
23
25
  download_source
24
- get_available_rolls
26
+ process_files
25
27
  end
26
28
 
27
29
  def create_tmp_dir
@@ -91,14 +93,20 @@ private
91
93
 
92
94
  # Get source rolls from tmp directory
93
95
  #
94
- def get_available_rolls
96
+ def process_files
95
97
  Dir.glob(File.join(@tmp_dir, ROLL_FILE_GLOB)).map do |r|
96
98
  name = File.basename(r, '.rb').to_sym
99
+
97
100
  tmp_path = Pathname.new @@root_tmp_dir
98
101
  full_path = Pathname.new r
99
102
  require_path = full_path.relative_path_from(tmp_path).to_s.chomp('.rb')
100
103
 
101
- @available_rolls[name] = require_path
104
+ # if add file to the correct hash
105
+ if r.include?('roll_model.rb')
106
+ @roll_models[name] = require_path
107
+ else
108
+ @available_rolls[name] = require_path
109
+ end
102
110
  end
103
111
  end
104
112
 
@@ -115,51 +115,67 @@ describe Yuyi::Cli do
115
115
  end
116
116
 
117
117
  describe '#write_to_file' do
118
- before do
119
- CliTest.write_to_file 'test', 'foo'
120
- end
121
-
122
118
  after do
123
- FileUtils.rm 'test'
119
+ FileUtils.rm Dir.glob('write_to_file*')
124
120
  end
125
121
 
126
122
  it 'should create a file if it doesnt exist' do
127
- expect(File.exists?('test')).to be true
123
+ CliTest.write_to_file 'write_to_file_create', 'foo'
124
+
125
+ expect(File.exists?('write_to_file_create')).to be true
128
126
  end
129
127
 
130
128
  it 'should append to the file' do
131
- CliTest.write_to_file 'test', 'bar'
132
- expect(File.open('test').read).to eq "foo\nbar\n"
129
+ CliTest.write_to_file 'write_to_file_append', 'foo'
130
+ CliTest.write_to_file 'write_to_file_append', 'bar'
131
+
132
+ expect(File.open('write_to_file_append').read).to eq "foo\nbar\n"
133
133
  end
134
134
 
135
- it 'should accept multiple text arguments' do
136
- CliTest.write_to_file 'test', 'arg1', 'arg2'
137
- expect(File.open('test').read).to eq "foo\narg1\narg2\n"
135
+ it 'should accept multiple string arguments' do
136
+ CliTest.write_to_file 'write_to_file_strings', 'line 1', 'line 2'
137
+
138
+ expect(File.open('write_to_file_strings').read).to eq "line 1\nline 2\n"
139
+ end
140
+
141
+ it 'should accept an array argument' do
142
+ CliTest.write_to_file 'write_to_file_array', ['line 1', 'line 2']
143
+
144
+ expect(File.open('write_to_file_array').read).to eq "line 1\nline 2\n"
138
145
  end
139
146
 
140
147
  it 'should not add a line if it already exists' do
141
- CliTest.write_to_file 'test', 'foo'
142
- expect(File.open('test').read).to eq "foo\n"
148
+ CliTest.write_to_file 'write_to_file_exists', 'foo'
149
+ CliTest.write_to_file 'write_to_file_exists', 'foo'
150
+
151
+ expect(File.open('write_to_file_exists').read).to eq "foo\n"
143
152
  end
144
153
  end
145
154
 
146
155
  describe '#delete_from_file' do
147
- before do
148
- CliTest.write_to_file 'test', 'foo', 'remove1', 'remove2', 'bar'
149
- end
150
-
151
156
  after do
152
- FileUtils.rm 'test'
157
+ FileUtils.rm Dir.glob('delete_from_file*')
153
158
  end
154
159
 
155
160
  it 'should remove a line from the file' do
156
- CliTest.delete_from_file 'test', 'remove1'
157
- expect(File.open('test').read).to eq "foo\nremove2\nbar\n"
161
+ CliTest.write_to_file 'delete_from_file', 'foo', 'remove', 'bar'
162
+ CliTest.delete_from_file 'delete_from_file', 'remove'
163
+
164
+ expect(File.open('delete_from_file').read).to eq "foo\nbar\n"
158
165
  end
159
166
 
160
- it 'should accept multiple text arguments' do
161
- CliTest.delete_from_file 'test', 'remove1', 'remove2'
162
- expect(File.open('test').read).to eq "foo\nbar\n"
167
+ it 'should accept multiple string arguments' do
168
+ CliTest.write_to_file 'delete_from_file_strings', 'foo', 'remove 1', 'remove 2', 'bar'
169
+ CliTest.delete_from_file 'delete_from_file_strings', 'remove 1', 'remove 2'
170
+
171
+ expect(File.open('delete_from_file_strings').read).to eq "foo\nbar\n"
172
+ end
173
+
174
+ it 'should accept an array argument' do
175
+ CliTest.write_to_file 'delete_from_file_array', 'foo', 'remove 1', 'remove 2', 'bar'
176
+ CliTest.delete_from_file 'delete_from_file_array', ['remove 1', 'remove 2']
177
+
178
+ expect(File.open('delete_from_file_array').read).to eq "foo\nbar\n"
163
179
  end
164
180
  end
165
181
 
@@ -7,7 +7,7 @@ describe Yuyi::Roll do
7
7
  allow(Yuyi::Menu).to receive(:options).and_return({ :foo => 'menu option' })
8
8
  allow(Yuyi::Menu).to receive(:on_the_menu?).and_return false
9
9
 
10
- class TestRoll < Yuyi::Roll
10
+ class Yuyi::TestRoll < Yuyi::Roll
11
11
  pre_install { :pre_install }
12
12
  install { :install }
13
13
  post_install { :post_install }
@@ -38,18 +38,30 @@ describe Yuyi::Roll do
38
38
  allow(Yuyi::Menu).to receive(:on_the_menu?).and_call_original
39
39
  end
40
40
 
41
+ describe '.class_to_title' do
42
+ it 'should render a title' do
43
+ expect(Yuyi::Roll.class_to_title('Yuyi::RollModel::FooBar')).to eq 'Foo Bar'
44
+ end
45
+ end
46
+
47
+ describe '.caller_to_file_name' do
48
+ it 'should render a file name' do
49
+ expect(Yuyi::Roll.caller_to_file_name(['/foo/bar/foo_bar.rb'])).to eq :foo_bar
50
+ end
51
+ end
52
+
41
53
  context 'when inherited' do
42
54
  it 'should add the roll to the menu' do
43
55
  allow(Yuyi::Menu).to receive :add_roll
44
56
 
45
- class TestInheritRoll < Yuyi::Roll
57
+ class Yuyi::TestInheritRoll < Yuyi::Roll
46
58
  install {}
47
59
  uninstall {}
48
60
  upgrade {}
49
61
  installed? {}
50
62
  end
51
63
 
52
- expect(Yuyi::Menu).to have_received(:add_roll).with :roll_spec, TestInheritRoll
64
+ expect(Yuyi::Menu).to have_received(:add_roll).with :roll_spec, Yuyi::TestInheritRoll
53
65
  end
54
66
 
55
67
  # DSL Methods
@@ -60,49 +72,49 @@ describe Yuyi::Roll do
60
72
  end
61
73
 
62
74
  it 'should create a title' do
63
- expect(TestRoll.title).to eq 'Test Roll'
75
+ expect(Yuyi::TestRoll.title).to eq 'Test Roll'
64
76
  end
65
77
 
66
78
  it 'should create a file name' do
67
- expect(TestRoll.file_name).to eq :roll_spec
79
+ expect(Yuyi::TestRoll.file_name).to eq :roll_spec
68
80
  end
69
81
 
70
82
  it 'should respond to .pre_install' do
71
- expect(TestRoll.pre_install).to be_a Proc
83
+ expect(Yuyi::TestRoll.pre_install).to be_a Proc
72
84
  end
73
85
 
74
86
  it 'should respond to .install' do
75
- expect(TestRoll.install).to be_a Proc
87
+ expect(Yuyi::TestRoll.install).to be_a Proc
76
88
  end
77
89
 
78
90
  it 'should respond to .post_install' do
79
- expect(TestRoll.post_install).to be_a Proc
91
+ expect(Yuyi::TestRoll.post_install).to be_a Proc
80
92
  end
81
93
 
82
94
  it 'should respond to .uninstall' do
83
- expect(TestRoll.uninstall).to be_a Proc
95
+ expect(Yuyi::TestRoll.uninstall).to be_a Proc
84
96
  end
85
97
 
86
98
  it 'should respond to .upgrade' do
87
- expect(TestRoll.upgrade).to be_a Proc
99
+ expect(Yuyi::TestRoll.upgrade).to be_a Proc
88
100
  end
89
101
 
90
102
  it 'should respond to .installed?' do
91
- expect(TestRoll.installed?).to be_a Proc
103
+ expect(Yuyi::TestRoll.installed?).to be_a Proc
92
104
  end
93
105
 
94
106
  it 'should return .dependencies' do
95
- expect(TestRoll.dependencies).to eq([:foo])
107
+ expect(Yuyi::TestRoll.dependencies).to eq([:foo])
96
108
  end
97
109
 
98
110
  it 'should return .options' do
99
- expect(TestRoll.options[:foo][:default]).to eq 'foo default'
111
+ expect(Yuyi::TestRoll.options[:foo][:default]).to eq 'foo default'
100
112
  end
101
113
  end
102
114
 
103
115
  context 'when initialized' do
104
116
  before do
105
- @test_roll = TestRoll.new
117
+ @test_roll = Yuyi::TestRoll.new
106
118
  end
107
119
 
108
120
  it 'should return the title' do
@@ -165,7 +177,7 @@ describe Yuyi::Roll do
165
177
 
166
178
  context '#order' do
167
179
  before do
168
- @roll = TestRoll.new
180
+ @roll = Yuyi::TestRoll.new
169
181
  allow(@roll).to receive(:install)
170
182
  allow(@roll).to receive(:uninstall)
171
183
  allow(@roll).to receive(:upgrade)
@@ -217,3 +229,49 @@ describe Yuyi::Roll do
217
229
  end
218
230
  end
219
231
  end
232
+
233
+ describe 'Yuyi::RollModel' do
234
+ before do
235
+ allow(Yuyi::Menu).to receive(:add_roll)
236
+
237
+ class Yuyi::FooRollModel < Yuyi::Roll
238
+ def self.inherited klass; add_roll klass, caller; end
239
+ def self.foo_name name
240
+ @@name = name
241
+ installed? { false }
242
+ end
243
+
244
+ end
245
+
246
+ class Yuyi::FooModelRoll < Yuyi::FooRollModel
247
+ foo_name 'Foo Name'
248
+ install do
249
+ @@name
250
+ end
251
+
252
+ installed? { true }
253
+ end
254
+ end
255
+
256
+ after do
257
+ allow(Yuyi::Menu).to receive(:add_roll).and_call_original
258
+ end
259
+
260
+ it 'should not add the roll model' do
261
+ class Yuyi::BarRollModel < Yuyi::Roll; end
262
+ expect(Yuyi::Menu).to_not have_received(:add_roll).with :roll_spec, Yuyi::BarRollModel
263
+ end
264
+
265
+ it 'should add the inherited roll' do
266
+ class Yuyi::FooInheritedRoll < Yuyi::FooRollModel; end
267
+ expect(Yuyi::Menu).to have_received(:add_roll).with :roll_spec, Yuyi::FooInheritedRoll
268
+ end
269
+
270
+ it 'should use the roll model methods' do
271
+ expect(Yuyi::FooModelRoll.new.send(:install)).to eq 'Foo Name'
272
+ end
273
+
274
+ it 'should prefer the roll methods over the model methods' do
275
+ expect(Yuyi::FooModelRoll.new.send(:installed?)).to be true
276
+ end
277
+ 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: 0.0.8
4
+ version: 1.0.0
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-06-16 00:00:00.000000000 Z
11
+ date: 2014-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec