summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2017-08-02 15:13:27 -0500
committerSamuel Giddins <segiddins@segiddins.me>2017-08-02 15:13:27 -0500
commit3f1c69c3b00d3cf53a4026b779b977d6ecdc42da (patch)
tree6625093928ba72bad4c6b888d5a1e07d3d388321
parentfbf6c389b072f42587be5954be2fc7f051afc184 (diff)
downloadbundler-seg-json-gemfile.tar.gz
Rudimentary JSON gemfileseg-json-gemfile
-rw-r--r--lib/bundler/definition.rb12
-rw-r--r--lib/bundler/dsl.rb18
2 files changed, 29 insertions, 1 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 634b2201f6..b9a26ba0e7 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -27,6 +27,18 @@ module Bundler
@static_gemfile
end
+ def to_json
+ require "json"
+ JSON.pretty_generate(
+ "dependencies" => Hash[dependencies.map {|d| [d.to_s, d.options_to_lock] }.sort_by(&:first)],
+ "sources" => sources.lock_sources.map {|s| [s.class.name.split("::").last, s.options] },
+ "ruby_version" => ruby_version,
+ "optional_groups" => optional_groups,
+ )
+ end
+
+ def self.from_json; end
+
# Given a gemfile and lockfile creates a Bundler definition
#
# @param gemfile [Pathname] Path to Gemfile
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb
index fe6d56510d..2fefc8e00c 100644
--- a/lib/bundler/dsl.rb
+++ b/lib/bundler/dsl.rb
@@ -45,7 +45,23 @@ module Bundler
@gemfile = expanded_gemfile_path
@gemfiles << expanded_gemfile_path
contents ||= Bundler.read_file(@gemfile.to_s)
- instance_eval(contents.dup.untaint, gemfile.to_s, 1)
+ if gemfile.to_s.end_with?(".json")
+ require "json"
+ json = JSON.parse(contents)
+ json["dependencies"].each do |dep, opts|
+ next unless dep =~ /^(.+?) \((.+)\)$/
+ _, name, reqs = *Regexp.last_match
+ reqs = reqs.split(", ")
+ gem(name, *reqs, opts)
+ end
+ json["sources"].each do |name, options|
+ raise "unsupported source #{name}" unless name == "Rubygems"
+ options["remotes"].each {|r| source r }
+ end
+ Array(json["eval_gemfile"]).each {|gf| eval_gemfile gf }
+ else
+ instance_eval(contents.dup.untaint, gemfile.to_s, 1)
+ end
rescue Exception => e
message = "There was an error " \
"#{e.is_a?(GemfileEvalError) ? "evaluating" : "parsing"} " \