Skip to content

Commit

Permalink
Add support for source block
Browse files Browse the repository at this point in the history
This allow you to use source block in both Appraisals and Gemfile.

Close #99
  • Loading branch information
sikachu committed Aug 13, 2015
1 parent 7adf764 commit 4cc1596
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/appraisal/appraisal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def gem(*args)
gemfile.gem(*args)
end

def source(*args)
gemfile.source(*args)
def source(*args, &block)
gemfile.source(*args, &block)
end

def ruby(*args)
Expand Down
15 changes: 11 additions & 4 deletions lib/appraisal/bundler_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class BundlerDSL
attr_reader :dependencies

PARTS = %w(source ruby_version git_sources path_sources dependencies groups
platforms gemspec)
platforms source_blocks gemspec)

def initialize
@sources = []
Expand All @@ -17,6 +17,7 @@ def initialize
@platforms = OrderedHash.new
@git_sources = OrderedHash.new
@path_sources = OrderedHash.new
@source_blocks = OrderedHash.new
end

def run(&block)
Expand All @@ -39,8 +40,13 @@ def platforms(*names, &block)

alias_method :platform, :platforms

def source(source)
@sources << source
def source(source, &block)
if block_given?
@source_blocks[source] ||= Source.new(source)
@source_blocks[source].run(&block)
else
@sources << source
end
end

def ruby(ruby_version)
Expand Down Expand Up @@ -103,7 +109,8 @@ def #{method_name}_entry_for_dup
METHODS
end

[:git_sources, :path_sources, :platforms, :groups].each do |method_name|
[:git_sources, :path_sources, :platforms, :groups, :source_blocks].
each do |method_name|
class_eval <<-METHODS, __FILE__, __LINE__
private
Expand Down
3 changes: 2 additions & 1 deletion lib/appraisal/gemfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
module Appraisal
autoload :Gemspec, "appraisal/gemspec"
autoload :GitSource, "appraisal/git_source"
autoload :PathSource, "appraisal/path_source"
autoload :Group, "appraisal/group"
autoload :PathSource, "appraisal/path_source"
autoload :Platform, "appraisal/platform"
autoload :Source, "appraisal/source"

# Load bundler Gemfiles and merge dependencies
class Gemfile < BundlerDSL
Expand Down
30 changes: 30 additions & 0 deletions lib/appraisal/source.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require "appraisal/bundler_dsl"
require "appraisal/utils"

module Appraisal
class Source < BundlerDSL
def initialize(source)
super()
@source = source
end

def to_s
formatted_output indent(super)
end

# :nodoc:
def for_dup
formatted_output indent(super)
end

private

def formatted_output(output_dependencies)
<<-OUTPUT.strip
source #{@source.inspect} do
#{output_dependencies}
end
OUTPUT
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe 'Appraisals file Bundler DSL compatibility' do
it 'supports all Bundler DSL in Appraisals file' do
build_gems %w(bagel orange_juice milk waffle coffee ham)
build_gems %w(bagel orange_juice milk waffle coffee ham sausage pancake)
build_git_gem 'egg'

build_gemfile <<-Gemfile
Expand Down Expand Up @@ -31,6 +31,10 @@
end
end
source "https://other-rubygems.org" do
gem "sausage"
end
gem 'appraisal', :path => #{PROJECT_ROOT.inspect}
Gemfile

Expand Down Expand Up @@ -61,6 +65,10 @@
gem 'yoghurt'
end
source "https://other-rubygems.org" do
gem "pancake"
end
gemspec
end
Appraisals
Expand Down Expand Up @@ -108,6 +116,11 @@
end
end
source "https://other-rubygems.org" do
gem "sausage"
gem "pancake"
end
gemspec :path => "../"
Gemfile
end
Expand Down

0 comments on commit 4cc1596

Please sign in to comment.