gemist 0.0.5 → 0.1.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.
- data/HISTORY.md +6 -0
- data/README.md +19 -17
- data/lib/gemist.rb +42 -10
- data/test/fixtures/lock/Gemfile +1 -0
- data/test/fixtures/lock/Gemfile.lock +15 -0
- data/test/lock_test.rb +18 -0
- data/test/test_helper.rb +7 -2
- metadata +5 -2
data/HISTORY.md
CHANGED
data/README.md
CHANGED
@@ -1,18 +1,25 @@
|
|
1
1
|
# Gemist
|
2
2
|
#### An extremely minimal solution to gem isolation
|
3
3
|
|
4
|
-
|
4
|
+
Gemist is a solution to load the correct gems for a project based on a Gemfile
|
5
|
+
manifest.
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
Gemist is a leaner (4kb), faster runtime that is Bundler-compatible. It does not
|
8
|
+
actually require Bundler.
|
8
9
|
|
9
10
|
## Getting started
|
10
11
|
|
12
|
+
Install it:
|
13
|
+
|
14
|
+
$ gem install gemist
|
15
|
+
|
11
16
|
Make a file in your project called `Gemfile`.
|
12
17
|
|
13
18
|
``` ruby
|
14
19
|
# Gemfile
|
15
20
|
gem "sinatra"
|
21
|
+
gem "haml"
|
22
|
+
gem "sass"
|
16
23
|
gem "ohm", "0.1.3"
|
17
24
|
|
18
25
|
# These will only be for the development environment
|
@@ -22,10 +29,13 @@ end
|
|
22
29
|
|
23
30
|
# You may specify multiple files to be required
|
24
31
|
gem "rails", ">= 3.0", require: ['rails', 'action_controller']
|
32
|
+
|
33
|
+
# You can also specify more than one version requirement
|
34
|
+
gem "compass", "~> 0.11.1", "<= 0.11.5"
|
25
35
|
```
|
26
36
|
|
27
37
|
In your project file, do this.
|
28
|
-
This `require`s the gems defined in the Gemfile
|
38
|
+
This `require`s the gems defined in the Gemfile based on the `RACK_ENV`.
|
29
39
|
|
30
40
|
``` ruby
|
31
41
|
require 'gemist'
|
@@ -77,18 +87,18 @@ handle.
|
|
77
87
|
|
78
88
|
### Freezing gem versions
|
79
89
|
|
80
|
-
|
90
|
+
If your project has a Bundler-generated `Gemfile.lock` file, Gemist will use it.
|
91
|
+
This file can be generated using `bundle update --local`. Note that this is
|
92
|
+
completely optional!
|
81
93
|
|
82
|
-
|
83
|
-
|
94
|
+
Also, to ensure your app will work with future gem releases, you should add
|
95
|
+
versions like so (using `~>` is highly recommended):
|
84
96
|
|
85
97
|
``` ruby
|
86
98
|
# Gemfile
|
87
99
|
gem "sinatra", "~> 1.1"
|
88
100
|
```
|
89
101
|
|
90
|
-
If you need a Gemfile.lock for whatever reason, use `bundle update --local`.
|
91
|
-
|
92
102
|
### Vendoring gems
|
93
103
|
|
94
104
|
Gemist does NOT vendor gems for you. Rubygems helps you with that already!
|
@@ -148,14 +158,6 @@ Benchmark.measure { require 'bundler'; Bundler.require } #=> 2.5s average
|
|
148
158
|
Benchmark.measure { require 'gemist'; Gemist.require } #=> 1.6s average
|
149
159
|
```
|
150
160
|
|
151
|
-
## Don't use this
|
152
|
-
|
153
|
-
This is merely a proof-of-concept. It works (very well), but:
|
154
|
-
|
155
|
-
1. The world has enough gem management tools, it doesn't need another.
|
156
|
-
|
157
|
-
2. Bundler is better (though it's more bloated and does more things).
|
158
|
-
|
159
161
|
## Not going to happen
|
160
162
|
|
161
163
|
Gemist will never have:
|
data/lib/gemist.rb
CHANGED
@@ -2,7 +2,7 @@ require 'ostruct'
|
|
2
2
|
|
3
3
|
# Gem environment manager.
|
4
4
|
module Gemist
|
5
|
-
VERSION = "0.0
|
5
|
+
VERSION = "0.1.0"
|
6
6
|
|
7
7
|
def self.version
|
8
8
|
VERSION
|
@@ -72,6 +72,10 @@ class Gemist::Gemfile
|
|
72
72
|
Dir["./{Gemistfile,Gemfile,Isolate}"].first
|
73
73
|
end
|
74
74
|
|
75
|
+
def self.lockfile_path
|
76
|
+
Dir["./{Gemistfile,Gemfile,Isolate}.lock"].first
|
77
|
+
end
|
78
|
+
|
75
79
|
# Checks if the project has a Gemfile manifest.
|
76
80
|
def self.exists?
|
77
81
|
!!path
|
@@ -79,11 +83,25 @@ class Gemist::Gemfile
|
|
79
83
|
|
80
84
|
# Returns a Gemfile instance made from the project's manifest.
|
81
85
|
def self.load
|
82
|
-
new
|
86
|
+
new(File.read(path), lockfile_contents) if exists?
|
83
87
|
end
|
84
88
|
|
85
|
-
def initialize(contents)
|
89
|
+
def initialize(contents, lockfile)
|
86
90
|
instance_eval contents
|
91
|
+
|
92
|
+
# Parse the lockfile
|
93
|
+
if lockfile
|
94
|
+
lockfile.split("\n").each { |s|
|
95
|
+
name, version = s.scan(/^ ([^ ]+) \(([0-9].*?)\)$/).first
|
96
|
+
gem = self[name]
|
97
|
+
gem.versions = [version] if gem
|
98
|
+
}
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Returns a gem
|
103
|
+
def [](name)
|
104
|
+
gems.select { |gem| gem.name == name }.first
|
87
105
|
end
|
88
106
|
|
89
107
|
# The list of gems the Gemfile. Returns an array of Gem instances.
|
@@ -96,7 +114,11 @@ class Gemist::Gemfile
|
|
96
114
|
gems.select { |g| g.group == nil || g.group.include?(env.to_s.to_sym) }
|
97
115
|
end
|
98
116
|
|
99
|
-
|
117
|
+
protected
|
118
|
+
def self.lockfile_contents
|
119
|
+
File.read(lockfile_path) if lockfile_path
|
120
|
+
end
|
121
|
+
|
100
122
|
# (DSL) Adds a gem.
|
101
123
|
#
|
102
124
|
# == Example
|
@@ -113,7 +135,13 @@ private
|
|
113
135
|
options[:version] ||= args
|
114
136
|
options[:group] ||= @group
|
115
137
|
|
116
|
-
|
138
|
+
gem = self[name]
|
139
|
+
|
140
|
+
if gem
|
141
|
+
gem.update options
|
142
|
+
else
|
143
|
+
self.gems << Gemist::Gem.new(options)
|
144
|
+
end
|
117
145
|
end
|
118
146
|
|
119
147
|
# (DSL) Defines a group.
|
@@ -144,11 +172,15 @@ class Gemist::Gem
|
|
144
172
|
attr_accessor :group
|
145
173
|
attr_reader :error
|
146
174
|
|
147
|
-
def initialize(options)
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
175
|
+
def initialize(options={})
|
176
|
+
update options
|
177
|
+
end
|
178
|
+
|
179
|
+
def update(options={})
|
180
|
+
self.name = options[:name] unless options[:name].nil?
|
181
|
+
self.versions = options[:version] unless options[:version].nil?
|
182
|
+
self.group = options[:group] unless options[:group].nil?
|
183
|
+
self.require = options[:require] unless options[:require].nil?
|
152
184
|
self.require = self.name if self.require.nil?
|
153
185
|
end
|
154
186
|
|
@@ -0,0 +1 @@
|
|
1
|
+
gem "sinatra", "~> 1.2.6"
|
data/test/lock_test.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class LockTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
Dir.chdir fx('lock/')
|
6
|
+
use_gemfile nil
|
7
|
+
end
|
8
|
+
|
9
|
+
teardown do
|
10
|
+
Dir.chdir fx
|
11
|
+
end
|
12
|
+
|
13
|
+
test "Gemfile.lock" do
|
14
|
+
Gem.expects(:activate).with('sinatra', '1.2.6').returns(true)
|
15
|
+
|
16
|
+
Gemist.setup
|
17
|
+
end
|
18
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -20,11 +20,16 @@ class Test::Unit::TestCase
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def fixture(path)
|
23
|
-
|
23
|
+
fx path
|
24
24
|
end
|
25
25
|
|
26
26
|
def use_gemfile(what)
|
27
|
-
ENV['GEMFILE'] = fixture(what)
|
27
|
+
ENV['GEMFILE'] = what.nil? ? nil : fixture(what)
|
28
28
|
Gemist.class_variable_set :@@gemfile, nil
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
def fx(path='')
|
33
|
+
File.expand_path("../fixtures/#{path}", __FILE__)
|
34
|
+
end
|
35
|
+
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: gemist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0
|
5
|
+
version: 0.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Rico Sta. Cruz
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-28 00:00:00 +08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -29,9 +29,12 @@ files:
|
|
29
29
|
- lib/gemist.rb
|
30
30
|
- test/bogus_test.rb
|
31
31
|
- test/fixtures/bogus.gemfile
|
32
|
+
- test/fixtures/lock/Gemfile
|
33
|
+
- test/fixtures/lock/Gemfile.lock
|
32
34
|
- test/fixtures/require.gemfile
|
33
35
|
- test/fixtures/sample.gemfile
|
34
36
|
- test/gemist_test.rb
|
37
|
+
- test/lock_test.rb
|
35
38
|
- test/require_test.rb
|
36
39
|
- test/test_helper.rb
|
37
40
|
- HISTORY.md
|