ensurable 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.gitignore +10 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +65 -0
- data/Rakefile +10 -0
- data/ensurable.gemspec +22 -0
- data/lib/ensurable.rb +51 -0
- data/lib/ensurable/now.rb +18 -0
- data/lib/ensurable/version.rb +3 -0
- data/lib/ensurables/git.rb +11 -0
- data/lib/ensurables/redis.rb +10 -0
- data/test/ensurable_test.rb +85 -0
- data/test/helper.rb +13 -0
- metadata +123 -0
data/.gemtest
ADDED
File without changes
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Jesse Storimer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
Ensurable
|
2
|
+
=========
|
3
|
+
|
4
|
+
FYI this is very alpha software, also it's not meant to be used in production. Actually it aborts in production so...
|
5
|
+
|
6
|
+
Use Case
|
7
|
+
-------
|
8
|
+
|
9
|
+
With Bundler we now have a great way of defining our gem deps and ensuring that all devs/machines are using the same set of gems, same versions, and all.
|
10
|
+
|
11
|
+
This gem attempts to do something similar for system deps (like development tools, software an app depends on, databases, etc.).
|
12
|
+
|
13
|
+
Usually this isn't really an issue because these kinds of tools aren't developed as quickly as rubygems are, however I have run into issues like this. If a coworker of mine is using Redis 1.x and I am using Redis 2.x we will see subtle differences in our output. This gem aims to make sure stuff like this can't happen.
|
14
|
+
|
15
|
+
Installation
|
16
|
+
-----------
|
17
|
+
|
18
|
+
gem i ensurable
|
19
|
+
|
20
|
+
In your Gemfile:
|
21
|
+
|
22
|
+
gem 'ensurable'
|
23
|
+
|
24
|
+
If you're using Rails you'll want to include this in your application.rb before the `require 'rails/all'`. This makes sure that this gem gets executed as early as possible and is able to ensure things before your app cries that it needs Msyql or Redis or something.
|
25
|
+
|
26
|
+
# config/application.rb
|
27
|
+
require File.expand_path('../boot', __FILE__)
|
28
|
+
|
29
|
+
require 'ensurable/now'
|
30
|
+
require 'rails/all'
|
31
|
+
|
32
|
+
Usage
|
33
|
+
-----
|
34
|
+
|
35
|
+
Ensurable provides a DSL for defining your apps system deps. Stick this in a file called `ensure.rb` in the root of your application.
|
36
|
+
|
37
|
+
# ensure.rb
|
38
|
+
installed 'git'
|
39
|
+
installed 'imagemagick'
|
40
|
+
|
41
|
+
running 'redis'
|
42
|
+
|
43
|
+
The `installed` method ensures that the given program is installed locally on the system. The `running` method ensures that the given program is currently running on the local system.
|
44
|
+
|
45
|
+
There's no magic here, ie. this gem doesn't try to guess what it means for a program to be installed or running. There is a class inside the gem for each of these deps that knows how to check these things.
|
46
|
+
|
47
|
+
Currently git and redis are the only supported deps. More are planned as needed.
|
48
|
+
|
49
|
+
Roadmap/TODO
|
50
|
+
-------
|
51
|
+
|
52
|
+
* Allow passing of version numbers when defining ensurables. eg. installed 'git', '> 1.7'
|
53
|
+
* Add another method to the Ensurable::#{program} API that lets users know how to install missing deps.
|
54
|
+
* Nicer error message when there's a missing dep. The default exception raised text is ugly.
|
55
|
+
|
56
|
+
Contributing
|
57
|
+
-----------
|
58
|
+
|
59
|
+
Just fork it and send a pull request.
|
60
|
+
|
61
|
+
License
|
62
|
+
------
|
63
|
+
|
64
|
+
MIT
|
65
|
+
|
data/Rakefile
ADDED
data/ensurable.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ensurable/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "ensurable"
|
7
|
+
s.version = Ensurable::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Jesse Storimer"]
|
10
|
+
s.email = ["jstorimer@gmail.com"]
|
11
|
+
s.homepage = "http://github.com/jstorimer/ensurable"
|
12
|
+
s.summary = %q{Kind of like Bundler, but for system deps, and a lot less features}
|
13
|
+
s.description = %q{Ensurable gives you a DSL for defining the system development dependencies of your app. It's kind of like Bundler, but for system deps, and does a lot less.}
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_development_dependency 'minitest'
|
20
|
+
s.add_development_dependency 'mocha'
|
21
|
+
s.add_development_dependency 'yard'
|
22
|
+
end
|
data/lib/ensurable.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Ensurable
|
2
|
+
class NotInstalled < StandardError; end
|
3
|
+
class NotRunning < StandardError; end
|
4
|
+
|
5
|
+
autoload :Git, 'ensurables/git'
|
6
|
+
autoload :Redis, 'ensurables/redis'
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
# Ensures that the given programs are installed/running.
|
11
|
+
#
|
12
|
+
# @param [File] optional file to read defining the ensurables
|
13
|
+
# @yield optional block to allow any ensurables to be required
|
14
|
+
def ensure(file = nil, &bloc)
|
15
|
+
abortables = []
|
16
|
+
abortables << (defined?(Rails) && Rails.respond_to?(:env) && Rails.env)
|
17
|
+
abortables << ENV['RAILS_ENV']
|
18
|
+
abortables << ENV['RACK_ENV']
|
19
|
+
|
20
|
+
abort('Ensurable is not meant for production use!') if abortables.any? {|a| a == 'production'}
|
21
|
+
|
22
|
+
if file
|
23
|
+
instance_eval file.read
|
24
|
+
else
|
25
|
+
instance_eval &bloc
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Ensures the the given program needs to be installed on the local system
|
30
|
+
#
|
31
|
+
# @param [String] prog the name of the program that should be installed. Requires that
|
32
|
+
# the constant Ensurable::program exists and follows that API.
|
33
|
+
# @raise [NotInstalled] raised when the given program is not installed on the local system
|
34
|
+
def installed(prog)
|
35
|
+
# Would be nice to have a nicer fail mechanism if the constant doesn't exist
|
36
|
+
klass = const_get(prog.capitalize)
|
37
|
+
|
38
|
+
raise NotInstalled.new("Looks like you don't have #{prog} installed.") unless klass.new.installed?
|
39
|
+
end
|
40
|
+
|
41
|
+
# Ensures that the given program is running on the local system
|
42
|
+
# @param [String] prog the name of the program that should be running. Requires that
|
43
|
+
# the constant Ensurable::program exists and follows that API.
|
44
|
+
# @raise [NotRunning] raised when the given program is not running on the local system
|
45
|
+
def running(prog)
|
46
|
+
klass = const_get(prog.capitalize)
|
47
|
+
|
48
|
+
raise NotRunning.new("Looks like you don't have #{prog} running.") unless klass.new.running?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'ensurable'
|
2
|
+
|
3
|
+
module Ensurable
|
4
|
+
module Now
|
5
|
+
def self.now!
|
6
|
+
dir = Dir.pwd
|
7
|
+
path = dir + '/ensure.rb'
|
8
|
+
if File.exist?(path)
|
9
|
+
Ensurable.ensure(File.new(path))
|
10
|
+
else
|
11
|
+
Dir.chdir('..')
|
12
|
+
now!
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Ensurable::Now.now!
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class EnsurableTest < MiniTest::Unit::TestCase
|
4
|
+
def test_aborts_if_rails_env_is_production
|
5
|
+
Rails.env = 'production'
|
6
|
+
|
7
|
+
Ensurable.expects(:abort)
|
8
|
+
Ensurable.ensure {}
|
9
|
+
|
10
|
+
Rails.env = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_no_abort_if_rails_env_is_development
|
14
|
+
Rails.env = 'development'
|
15
|
+
|
16
|
+
Ensurable.expects(:abort).never
|
17
|
+
Ensurable.ensure {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_abort_if_rails_env_var_is_production
|
21
|
+
ENV['RAILS_ENV'] = 'production'
|
22
|
+
|
23
|
+
Ensurable.expects(:abort)
|
24
|
+
Ensurable.ensure {}
|
25
|
+
|
26
|
+
ENV['RAILS_ENV'] = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_abort_if_rack_env_var_is_production
|
30
|
+
ENV['RACK_ENV'] = 'production'
|
31
|
+
|
32
|
+
Ensurable.expects(:abort)
|
33
|
+
Ensurable.ensure {}
|
34
|
+
|
35
|
+
ENV['RACK_ENV'] = nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_ensure_with_git_installed
|
39
|
+
Ensurable::Git.any_instance.expects(:installed?).returns(true)
|
40
|
+
|
41
|
+
Ensurable.ensure do
|
42
|
+
installed 'git'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_ensure_without_git_installed
|
47
|
+
Ensurable::Git.any_instance.expects(:installed?).returns(false)
|
48
|
+
|
49
|
+
assert_raises(Ensurable::NotInstalled) {
|
50
|
+
Ensurable.ensure do
|
51
|
+
installed 'git'
|
52
|
+
end
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_ensure_with_redis_running
|
57
|
+
Ensurable::Redis.any_instance.expects(:running?).returns(true)
|
58
|
+
|
59
|
+
Ensurable.ensure do
|
60
|
+
running 'redis'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_ensure_without_redis_running
|
65
|
+
Ensurable::Redis.any_instance.expects(:running?).returns(false)
|
66
|
+
|
67
|
+
assert_raises(Ensurable::NotRunning) {
|
68
|
+
Ensurable.ensure do
|
69
|
+
running 'redis'
|
70
|
+
end
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_ensure_with_file_arg_passed
|
75
|
+
Ensurable::Git.any_instance.expects(:installed?).returns(true)
|
76
|
+
|
77
|
+
file = File.new('ensure.rb', 'w+')
|
78
|
+
file.puts "installed 'git'"
|
79
|
+
file.seek(0)
|
80
|
+
|
81
|
+
Ensurable.ensure(file)
|
82
|
+
|
83
|
+
File.delete(file.path)
|
84
|
+
end
|
85
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ensurable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jesse Storimer
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-02 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: minitest
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: mocha
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: yard
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
description: Ensurable gives you a DSL for defining the system development dependencies of your app. It's kind of like Bundler, but for system deps, and does a lot less.
|
64
|
+
email:
|
65
|
+
- jstorimer@gmail.com
|
66
|
+
executables: []
|
67
|
+
|
68
|
+
extensions: []
|
69
|
+
|
70
|
+
extra_rdoc_files: []
|
71
|
+
|
72
|
+
files:
|
73
|
+
- .gemtest
|
74
|
+
- .gitignore
|
75
|
+
- Gemfile
|
76
|
+
- MIT-LICENSE
|
77
|
+
- README.markdown
|
78
|
+
- Rakefile
|
79
|
+
- ensurable.gemspec
|
80
|
+
- lib/ensurable.rb
|
81
|
+
- lib/ensurable/now.rb
|
82
|
+
- lib/ensurable/version.rb
|
83
|
+
- lib/ensurables/git.rb
|
84
|
+
- lib/ensurables/redis.rb
|
85
|
+
- test/ensurable_test.rb
|
86
|
+
- test/helper.rb
|
87
|
+
has_rdoc: true
|
88
|
+
homepage: http://github.com/jstorimer/ensurable
|
89
|
+
licenses: []
|
90
|
+
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
hash: 3
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
version: "0"
|
114
|
+
requirements: []
|
115
|
+
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 1.5.0
|
118
|
+
signing_key:
|
119
|
+
specification_version: 3
|
120
|
+
summary: Kind of like Bundler, but for system deps, and a lot less features
|
121
|
+
test_files:
|
122
|
+
- test/ensurable_test.rb
|
123
|
+
- test/helper.rb
|