Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Start working on the environment.rb lock file

  • Loading branch information...
commit ee0e2c19536087dbe60fa2e00bfdb9354bf827bf 1 parent a7f60b7
Carl Lerche authored
View
26 lib/bubble.rb
@@ -21,16 +21,17 @@ class GemNotFound < StandardError; end
class VersionConflict < StandardError; end
class GemfileError < StandardError; end
- def self.setup(gemfile = nil)
+ def self.setup(gemfile = default_gemfile)
load(gemfile).setup
end
- def self.load(gemfile = nil)
- Environment.new definition(gemfile)
+ def self.load(gemfile = default_gemfile)
+ root = Pathname.new(gemfile).dirname
+ Environment.new root, definition(gemfile)
end
- def self.definition(gemfile = nil)
- lockfile = Pathname.new(gemfile || Definition.default_gemfile).dirname.join('omg.yml')
+ def self.definition(gemfile = default_gemfile)
+ lockfile = Pathname.new(gemfile || default_gemfile).dirname.join('omg.yml')
if lockfile.exist?
Definition.from_lock(lockfile)
else
@@ -49,4 +50,19 @@ def self.install_path
def self.cache
home.join("cache")
end
+
+private
+
+ def self.default_gemfile
+ current = Pathname.new(Dir.pwd)
+
+ until current.root?
+ filename = current.join("Gemfile")
+ return filename if filename.exist?
+ current = current.parent
+ end
+
+ raise GemfileNotFound, "The default Gemfile was not found"
+ end
+
end
View
14 lib/bubble/definition.rb
@@ -1,7 +1,7 @@
module Bubble
class Definition
def self.from_gemfile(gemfile)
- gemfile = Pathname.new(gemfile || default_gemfile).expand_path
+ gemfile = Pathname.new(gemfile).expand_path
unless gemfile.file?
raise GemfileNotFound, "`#{gemfile}` not found"
@@ -10,18 +10,6 @@ def self.from_gemfile(gemfile)
Dsl.evaluate(gemfile)
end
- def self.default_gemfile
- current = Pathname.new(Dir.pwd)
-
- until current.root?
- filename = current.join("Gemfile")
- return filename if filename.exist?
- current = current.parent
- end
-
- raise GemfileNotFound, "The default Gemfile was not found"
- end
-
def self.from_lock(lockfile)
# gemfile_definition = from_gemfile(nil)
locked_definition = Locked.new(YAML.load_file(lockfile))
View
33 lib/bubble/environment.rb
@@ -1,6 +1,9 @@
module Bubble
class Environment
- def initialize(definition)
+ attr_reader :root
+
+ def initialize(root, definition)
+ @root = root
@definition = definition
end
@@ -10,9 +13,9 @@ def setup
# Activate the specs
specs.each do |spec|
- $LOAD_PATH.unshift *spec.load_paths
Gem.loaded_specs[spec.name] = spec
end
+ $LOAD_PATH.unshift *load_paths
self
end
@@ -21,10 +24,9 @@ def dependencies
end
def lock
- yml = details.to_yaml
- File.open("#{Definition.default_gemfile.dirname}/omg.yml", 'w') do |f|
- f.puts yml
- end
+ FileUtils.mkdir_p("#{root}/vendor")
+ write_yml_lock
+ write_rb_lock
end
def specs
@@ -47,6 +49,10 @@ def sources
@definition.sources
end
+ def load_paths
+ specs.map { |s| s.load_paths }.flatten
+ end
+
def cripple_rubygems
# handle 1.9 where system gems are always on the load path
if defined?(::Gem)
@@ -68,6 +74,21 @@ def gem(*)
end
end
+ def write_rb_lock
+ template = File.read(File.expand_path("../templates/environment.erb", __FILE__))
+ erb = ERB.new(template, nil, '-')
+ File.open("#{root}/vendor/environment.rb", 'w') do |f|
+ f.puts erb.result(binding)
+ end
+ end
+
+ def write_yml_lock
+ yml = details.to_yaml
+ File.open("#{root}/vendor/lock.yml", 'w') do |f|
+ f.puts yml
+ end
+ end
+
def details
details = {}
details["sources"] = sources.map { |s| { s.class.name.split("::").last => s.options} }
View
6 lib/bubble/templates/environment.erb
@@ -0,0 +1,6 @@
+# DO NOT MODIFY THIS FILE
+module Bubble
+<% load_paths.each do |path| -%>
+ $LOAD_PATH.unshift "<%= path %>"
+<% end -%>
+end
Please sign in to comment.
Something went wrong with that request. Please try again.