Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verifies database adapter on a platform basis
It's normal to have in your Gemfile more than one platform (JRuby, MRI etc). Railbrazer, though, is not considering it when choosing the database adapter. It's also raising an exception on Gemfiles such as the following: ``` gem 'pg', platform: :mri gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby ``` With this change, we only select the gems that are defined for the current platform.
- Loading branch information
Showing
5 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Railblazer | ||
class Gem | ||
def initialize(name, args) | ||
@name = name | ||
@args = args.last || {} | ||
end | ||
|
||
def for_current_platform? | ||
(platform?(:jruby) && ruby_platform == "java") || | ||
(platform?(:mri) && ruby_platform != "java") || | ||
(args[:platform].nil?) | ||
end | ||
|
||
private | ||
|
||
attr_accessor :args | ||
|
||
def platform?(platform) | ||
Array(args[:platform]).include?(platform) | ||
end | ||
|
||
def ruby_platform | ||
RUBY_PLATFORM | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'spec_helper' | ||
|
||
describe Railblazer::Gem do | ||
describe "#for_current_platform?" do | ||
it "returns true if ruby platform is Java and gem platform is jruby" do | ||
gem = Railblazer::Gem.new("pg", [{platform: :jruby}]) | ||
gem.stubs(:ruby_platform).returns("java") | ||
gem.for_current_platform?.must_equal true | ||
end | ||
|
||
it "returns false if ruby platform is Java and gem platform is mri" do | ||
gem = Railblazer::Gem.new("pg", [{platform: :mri}]) | ||
gem.stubs(:ruby_platform).returns("java") | ||
gem.for_current_platform?.must_equal false | ||
end | ||
|
||
it "returns true if ruby platform is not Java and gem platform is mri" do | ||
gem = Railblazer::Gem.new("pg", [{platform: :mri}]) | ||
gem.stubs(:ruby_platform).returns("something_entirely_different") | ||
gem.for_current_platform?.must_equal true | ||
end | ||
|
||
it "returns false if ruby platform is not Java and gem platform is jruby" do | ||
gem = Railblazer::Gem.new("pg", [{platform: :jruby}]) | ||
gem.stubs(:ruby_platform).returns("something_entirely_different") | ||
gem.for_current_platform?.must_equal false | ||
end | ||
|
||
it "returns true if no gem platform is specified" do | ||
gem = Railblazer::Gem.new("pg", []) | ||
gem.stubs(:ruby_platform).returns("java") | ||
gem.for_current_platform?.must_equal true | ||
end | ||
|
||
it "works when platform is an array" do | ||
gem = Railblazer::Gem.new("pg", [{platform: [:jruby]}]) | ||
gem.stubs(:ruby_platform).returns("java") | ||
gem.for_current_platform?.must_equal true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters