diff options
author | Asutosh Palai <asupalai@gmail.com> | 2016-05-31 10:38:48 +0530 |
---|---|---|
committer | Asutosh Palai <asupalai@gmail.com> | 2016-07-03 09:38:56 +0530 |
commit | 40e6a351c64c9e729d9459dec7befe862c497e29 (patch) | |
tree | 82a5aa44aaae73313ae640bbdd9bc266e78194e5 /lib | |
parent | 317fb5b85a6fc95ddb22e97aa76da562ce2b3e25 (diff) | |
download | bundler-40e6a351c64c9e729d9459dec7befe862c497e29.tar.gz |
Working upto call to specs
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/dsl.rb | 15 | ||||
-rw-r--r-- | lib/bundler/plugin/api/source.rb | 29 | ||||
-rw-r--r-- | lib/bundler/source_list.rb | 14 |
3 files changed, 44 insertions, 14 deletions
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 30df983c..eca71fd0 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -127,8 +127,8 @@ module Bundler def source(source, *args, &blk) options = args.last.is_a?(Hash) ? args.pop.dup : nil - if options && options.key?(:type) && !@plugin_dsl - unless Bundler::Plugin.source?(options[:type]) + if options && options.key?(:type) + unless Plugin.source?(options[:type]) raise "No sources available for #{options[:type]}" end @@ -136,14 +136,13 @@ module Bundler raise InvalidOption, "You need to pass a block to #source with :type option" end - Bundler::Plugin.source(options[:type]).new.say_hi - throw "Source plugins are not implemented yet :P " - end - - source = normalize_source(source) - if block_given? + source_opts = normalize_hash(options).merge("uri" => source) + with_source(@sources.add_plugin_source(options["type"], source_opts), &blk) + elsif block_given? + source = normalize_source(source) with_source(@sources.add_rubygems_source("remotes" => source), &blk) else + source = normalize_source(source) check_primary_source_safety(@sources) @sources.add_rubygems_remote(source) end diff --git a/lib/bundler/plugin/api/source.rb b/lib/bundler/plugin/api/source.rb index 4f2022d9..be1c7857 100644 --- a/lib/bundler/plugin/api/source.rb +++ b/lib/bundler/plugin/api/source.rb @@ -2,8 +2,33 @@ module Bundler module Plugin::Api::Source - def say_hi - puts "Hi people" + attr_reader :uri + + def initialize(opts) + @options = opts + @uri = opts["uri"] + end + + def specs + index = Bundler::Index.new + + files = fetch_gemfiles + files.each do |file| + next unless spec = Bundler.load_gemspec(file) + spec.source = self + Bundler.rubygems.set_installed_by_version(spec) + # Validation causes extension_dir to be calculated, which depends + # on #source, so we validate here instead of load_gemspec + Bundler.rubygems.validate(spec) + + index << spec + end + + index + end + + def fetch_gemfile + raise "Source plugins need to define fetch_gemfile method" end end end diff --git a/lib/bundler/source_list.rb b/lib/bundler/source_list.rb index 0595cbdc..b9fb73f4 100644 --- a/lib/bundler/source_list.rb +++ b/lib/bundler/source_list.rb @@ -2,7 +2,8 @@ module Bundler class SourceList attr_reader :path_sources, - :git_sources + :git_sources, + :plugin_sources def initialize @path_sources = [] @@ -27,6 +28,10 @@ module Bundler add_source_to_list Source::Rubygems.new(options), @rubygems_sources end + def add_plugin_source(source, options = {}) + add_source_to_list Plugin.source(source).new(options), @plugin_sources + end + def add_rubygems_remote(uri) @rubygems_aggregate.add_remote(uri) @rubygems_aggregate @@ -92,9 +97,10 @@ module Bundler def source_list_for(source) case source - when Source::Git then git_sources - when Source::Path then path_sources - when Source::Rubygems then rubygems_sources + when Source::Git then git_sources + when Source::Path then path_sources + when Source::Rubygems then rubygems_sources + when Plugin::Base::Source then plugin_sources else raise ArgumentError, "Invalid source: #{source.inspect}" end end |