rockit-now 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ # Current changes
2
+
3
+ # 0.2.0 March 18, 2012
4
+
5
+ - Adding additional default configuration files, mimicking rake behavior
6
+ - Avoid failing for [if_service_not_running, if_command_missing] if the block returns true
7
+ - Add verbose mode to print all commands, accessible from the dsl :
8
+ - ```verbose_on```
9
+ - ```verbose_off```
10
+
11
+ # 0.1.0 March 18, 2012
12
+
13
+ - Initial DSL definitions for (see docs in [Rockit::Application]):
14
+ - ```if_file_changed```
15
+ - ```if_directory_changed```
16
+ - ```service```
17
+ - ```if_service_not_running```
18
+ - ```command```
19
+ - ```if_command_missing```
20
+ - ```if_first_time```
21
+ - ```if_string_changed```
22
+ - ```if_string_digest_changed```
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Rockit is a dsl to help setup, detect changes and keep your environment up-to-date so you can start working as fast as possible.
4
4
 
5
- ## Install - NOT AVAILABLE YET
5
+ ## Install
6
6
 
7
7
  ```gem install rockit-now```
8
8
 
@@ -18,12 +18,12 @@ Include in a ruby file :
18
18
 
19
19
  ```ruby
20
20
  require 'rockit'
21
- Rockit::Application.run
21
+ Rockit::Application.new.run
22
22
  ```
23
23
 
24
24
  ## RockitFile Configuration
25
25
 
26
- Rockit requires a RockitFile for configuration. This is where you use ruby code and some helpful methods to define your environment. It is highly recommended that you commit your configuration to ensure quick and easy setup.
26
+ Rockit requires a Rockitfile for configuration. This is where you use ruby code and some helpful methods to define your environment. It is highly recommended that you commit your configuration to ensure quick and easy setup.
27
27
 
28
28
  ### Commands and Services
29
29
 
@@ -53,20 +53,20 @@ end
53
53
  Applications environments are always changing and your local environment needs to react to them. For instance, when working in a rails team, migrations and gems are often changed and need to be updated. Add the following to your configurtion to detect changes and automatically keep stay up-to-date :
54
54
 
55
55
  ```ruby
56
- if_directory_changed "db/migrate" do
57
- run "rake db:migrate"
58
- end
59
-
60
56
  if_file_changed "Gemfile" do
61
57
  run "bundle"
62
58
  end
59
+
60
+ if_directory_changed "db/migrate" do
61
+ run "rake db:migrate"
62
+ end
63
63
  ```
64
64
 
65
65
  ### Documentation and Examples
66
66
 
67
- Documentation is available http://rubydoc.info/github/bwillis/rockit/master/frames
67
+ - Code docs are available http://rubydoc.info/github/bwillis/rockit/master/frames
68
68
 
69
- You can find [example configurations](http://github.com/bwillis/rockit/blob/master/example/Rockitfile)
69
+ - [example configurations](http://github.com/bwillis/rockit/blob/master/example/Rockitfile)
70
70
 
71
71
  # License
72
72
 
@@ -1,14 +1,15 @@
1
- # Rockitfile
1
+ #!/usr/bin/env ruby
2
+
3
+ # Example Rockitfile Configuration
2
4
 
3
5
  ###### Require Commands ######
4
6
 
5
7
  # command 'convert' is equivalent to
6
8
  if_command_missing "convert" do
7
- puts "required command 'convert' is not available."
8
- exit
9
+ run "brew install imagemagick"
9
10
  end
10
11
 
11
- ###### Required Service ######
12
+ ###### Required Services ######
12
13
 
13
14
  # service 'mysql' is equivalent to
14
15
  if_service_not_running "mysql" do
@@ -8,14 +8,24 @@ module Rockit
8
8
 
9
9
  class Application
10
10
 
11
+ # Default configuration file names
12
+ CONFIG_FILES = ['rockitfile', 'Rockitfile', 'rockitfile.rb', 'Rockitfile.rb']
13
+
11
14
  def initialize(store=nil)
12
15
  @hash_store = store || HashStore.new
16
+ @debug = false
17
+ end
18
+
19
+ # Turn on debugging
20
+ def debug(val=true)
21
+ @debug = val
13
22
  end
14
23
 
15
24
  # Run a Rockit configuration file and Rails dependency checks
16
25
  # unless turned off by configuration.
17
- def run(rockit_file="Rockitfile")
18
- raise ArgumentError unless File.exists?(rockit_file)
26
+ def run
27
+ rockit_file = CONFIG_FILES.select { |f| File.exists?(f) }.first
28
+ raise ArgumentError "No Rockitfile found (looking for: #{CONFIG_FILES.join(',')})" unless rockit_file
19
29
  Dsl.new(self).instance_eval(File.read(rockit_file), rockit_file)
20
30
  end
21
31
 
@@ -33,8 +43,8 @@ module Rockit
33
43
  # return only if it finishes successfully
34
44
  def command(command, options)
35
45
  options = {
36
- 'print_command' => false,
37
- 'failure_message' => "required command '#{command}' is not available."
46
+ 'print_command' => false,
47
+ 'failure_message' => "required command '#{command}' is not available."
38
48
  }.merge(string_keys(options))
39
49
  system_exit_on_error("which #{command}", options)
40
50
  end
@@ -48,8 +58,8 @@ module Rockit
48
58
  # return only if it finishes successfully
49
59
  def service(service_name, options={})
50
60
  options = {
51
- 'print_command' => false,
52
- 'failure_message' => "required service '#{service_name}' is not running."
61
+ 'print_command' => false,
62
+ 'failure_message' => "required service '#{service_name}' is not running."
53
63
  }.merge(string_keys(options))
54
64
  system_exit_on_error("ps ax | grep '#{service_name.gsub(/^(.)/, "[\\1]")}'", options)
55
65
  end
@@ -98,17 +108,20 @@ module Rockit
98
108
  # command - the system command you want to execute
99
109
  # options - 'error_message' - a message to print when command is not successful
100
110
  # 'print_command' - displays the command being run
101
- # 'failure_callback' - Proc to execute when the command fails
111
+ # 'failure_callback' - Proc to execute when the command fails. If a callback returns
112
+ # true then it will avoid
102
113
  # 'on_success' - Proc to execute when the command is successful
103
114
  #
104
115
  # returns only true, will perform exit() when not successful
105
116
  #
106
117
  def system_exit_on_error(command, options={})
107
118
  options = {'print_command' => true}.merge(string_keys(options))
108
- output command if options['print_command']
119
+ output command if options['print_command'] || @debug
109
120
  command_output = system_command(command)
121
+ output command_output if @debug
110
122
  unless last_process.success?
111
- options['on_failure'].call(command, options) if options['on_failure'].is_a?(Proc)
123
+ result = options['on_failure'].call(command, options) if options['on_failure'].is_a?(Proc)
124
+ return true if result
112
125
  output options['failure_message'] || command_output
113
126
  return exit(last_process.exitstatus)
114
127
  end
@@ -161,4 +174,4 @@ module Rockit
161
174
  end
162
175
 
163
176
  end
164
- end
177
+ end
@@ -6,6 +6,14 @@ module Rockit
6
6
  @app = app
7
7
  end
8
8
 
9
+ def verbose_on
10
+ @app.debug(true)
11
+ end
12
+
13
+ def verbose_off
14
+ @app.debug(false)
15
+ end
16
+
9
17
  def command(command, options={})
10
18
  @app.command(command, options)
11
19
  end
@@ -1,3 +1,3 @@
1
1
  module Rockit
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  describe Rockit::Application do
4
4
  before do
5
5
  @app = Rockit::Application.new({})
6
+ @app.stubs(:output)
6
7
  end
7
8
 
8
9
  def block_should_execute
@@ -15,6 +16,27 @@ describe Rockit::Application do
15
16
  lambda { |*args| fail }
16
17
  end
17
18
 
19
+ describe '#run' do
20
+ context 'running without a configuration file available' do
21
+ before do
22
+ File.exists?('Rockitfile').should_not be
23
+ end
24
+ it 'does raises an argument error' do
25
+ lambda { @app.run }.should raise_error
26
+ end
27
+ end
28
+ context 'running with a configuration file' do
29
+ before do
30
+ File.stubs(:exists?).returns(false)
31
+ File.stubs(:exists?).with('Rockitfile.rb').returns(true)
32
+ File.stubs(:read).with('Rockitfile.rb').returns("")
33
+ end
34
+ it 'does not raise an argument error' do
35
+ lambda { @app.run }.should_not raise_error
36
+ end
37
+ end
38
+ end
39
+
18
40
  describe '#clear_cache' do
19
41
  context 'when calling clear cache' do
20
42
  before do
@@ -29,6 +51,37 @@ describe Rockit::Application do
29
51
  end
30
52
  end
31
53
 
54
+ describe '#service' do
55
+ context 'when querying an unstarted service with a retry failure block' do
56
+ before do
57
+ last_process = mock()
58
+ @app.stubs(:last_process).returns(last_process)
59
+ last_process.stubs(:success?).returns(false,true)
60
+ end
61
+
62
+ it 'does not call system exit' do
63
+ @app.stubs(:exit).returns { fail }
64
+ @app.service('test', {:on_failure => lambda{|*a| true } })
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ describe '#command' do
71
+ context 'when executing a missing command and executing a retry failure block' do
72
+ before do
73
+ last_process = mock()
74
+ @app.stubs(:last_process).returns(last_process)
75
+ last_process.stubs(:success?).returns(false,true)
76
+ end
77
+
78
+ it 'does not call system exit' do
79
+ @app.stubs(:exit).returns { fail }
80
+ @app.command('test', {:on_failure => lambda{|*a| true } })
81
+ end
82
+ end
83
+ end
84
+
32
85
  describe '#if_directory_changed' do
33
86
  before do
34
87
  Dir.stubs(:glob).returns(['file1', 'file2'])
@@ -154,6 +207,14 @@ describe Rockit::Application do
154
207
  @app.stubs('last_process').returns(@last_process)
155
208
  end
156
209
 
210
+ context 'with verbose on' do
211
+ it 'calls output event with print_command off' do
212
+ @app.expects('output')
213
+ @app.debug(true)
214
+ @app.system_exit_on_error('failing command', {'print_command' => false})
215
+ end
216
+ end
217
+
157
218
  it 'calls exit' do
158
219
  @app.unstub('exit')
159
220
  lambda { @app.system_exit_on_error('failing command') }.should raise_error SystemExit
@@ -180,16 +241,22 @@ describe Rockit::Application do
180
241
  @app.system_exit_on_error('failing command', :failure_message => new_message)
181
242
  end
182
243
 
183
- it 'calls the failure callback' do
184
- block_called = false
185
- @app.system_exit_on_error('failing command', :on_failure => lambda { |a, b| block_called = true })
186
- block_called.should == true
244
+ context 'with a failure callback' do
245
+ it 'calls the failure callback' do
246
+ @app.system_exit_on_error('failing command', :on_failure => block_should_execute)
247
+ end
248
+ context 'that returns true' do
249
+ it 'does not call exit' do
250
+ @app.stubs(:exit).with { fail }
251
+ end
252
+ it 'does not return failure' do
253
+ @app.system_exit_on_error('failing command', :on_failure => lambda{ |*a| true } ).should == true
254
+ end
255
+ end
187
256
  end
188
257
 
189
258
  it 'does not call the success callback' do
190
- block_called = false
191
- @app.system_exit_on_error('failing command', :on_success => lambda { |a, b| block_called = true })
192
- block_called.should == false
259
+ @app.system_exit_on_error('failing command', :on_success => block_should_not_execute)
193
260
  end
194
261
  end
195
262
 
@@ -201,6 +268,24 @@ describe Rockit::Application do
201
268
  @last_process.stubs(:success?).returns(true)
202
269
  end
203
270
 
271
+ context 'with verbose on' do
272
+ it 'calls output event with print_command off' do
273
+ @app.expects('output')
274
+ @app.debug(true)
275
+ @app.system_exit_on_error('successful command', {'print_command' => false})
276
+ end
277
+
278
+ it 'can be turned on and off between calls' do
279
+ @app.debug(true)
280
+ @app.expects('output')
281
+ @app.system_exit_on_error('successful command', {'print_command' => false})
282
+
283
+ @app.debug(false)
284
+ @app.stubs('output').returns { fail }
285
+ @app.system_exit_on_error('successful command', {'print_command' => false})
286
+ end
287
+ end
288
+
204
289
  it 'does not exit' do
205
290
  @app.system_exit_on_error('successful command')
206
291
  end
@@ -211,15 +296,11 @@ describe Rockit::Application do
211
296
  end
212
297
 
213
298
  it 'does not call the failure callback' do
214
- block_called = false
215
- @app.system_exit_on_error('successful command', :on_failure => lambda { |a, b| blocked_called = true })
216
- block_called.should == false
299
+ @app.system_exit_on_error('successful command', :on_failure => block_should_not_execute)
217
300
  end
218
301
 
219
302
  it 'does call the success callback' do
220
- block_called = false
221
- @app.system_exit_on_error('successful command', :on_success => lambda { |a, b| block_called = true })
222
- block_called.should == true
303
+ @app.system_exit_on_error('successful command', :on_success => block_should_execute)
223
304
  end
224
305
  end
225
306
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rockit-now
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-18 00:00:00.000000000Z
12
+ date: 2012-03-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70136619827500 !ruby/object:Gem::Requirement
16
+ requirement: &70170043798600 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70136619827500
24
+ version_requirements: *70170043798600
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mocha
27
- requirement: &70136619827080 !ruby/object:Gem::Requirement
27
+ requirement: &70170043797640 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70136619827080
35
+ version_requirements: *70170043797640
36
36
  description: Check and verify external project and rails specific project dependencies.
37
37
  The script will cache results to ensure quick script execution each time.
38
38
  email:
@@ -45,6 +45,7 @@ files:
45
45
  - .gitignore
46
46
  - .rvmrc
47
47
  - .travis.yml
48
+ - CHANGELOG.md
48
49
  - Gemfile
49
50
  - Gemfile.lock
50
51
  - LICENSE