Permalink
Browse files

Set Psych as the YAML engine for Rubinius

Since the rubysl-yaml gem doesn't ship with Psych by default because of
its dependency on libyaml, on Rubinius, the default engine is Syck.

However, if we want to be able to run the application safely on
different rubies, we need to make people using Rubinius rely on Psych.

See http://git.io/uuLVag for further information.
  • Loading branch information...
robin850 committed Jul 23, 2014
1 parent 8c48a70 commit 558f8aa2ee80ee8cb859f0da9714dc93294c856b
Showing with 28 additions and 0 deletions.
  1. +6 −0 Gemfile
  2. +9 −0 railties/lib/rails/generators/app_base.rb
  3. +13 −0 railties/test/generators/app_generator_test.rb
View
@@ -87,6 +87,12 @@ platforms :jruby do
end
end
+platforms :rbx do
+ # The rubysl-yaml gem doesn't ship with Psych by default
+ # as it needs libyaml that isn't always available.
+ gem 'psych', '~> 2.0'
+end
+
# gems that are necessary for ActiveRecord tests with Oracle database
if ENV['ORACLE_ENHANCED']
platforms :ruby do
@@ -114,6 +114,7 @@ def gemfile_entries
jbuilder_gemfile_entry,
sdoc_gemfile_entry,
spring_gemfile_entry,
+ psych_gemfile_entry,
@extra_entries].flatten.find_all(&@gem_filter)
end
@@ -313,6 +314,14 @@ def spring_gemfile_entry
GemfileEntry.new('spring', nil, comment, group: :development)
end
+ def psych_gemfile_entry
+ return [] unless defined?(Rubinius)
+
+ comment = 'Use Psych as the YAML engine, instead of Syck, so serialized ' \
+ 'data can be read safely from different rubies (see http://git.io/uuLVag)'
+ GemfileEntry.new('psych', '~> 2.0', comment, platforms: :rbx)
+ end
+
def bundle_command(command)
say_status :run, "bundle #{command}"
@@ -488,6 +488,19 @@ def test_gitignore_when_non_sqlite3_db
end
end
+ def test_psych_gem
+ run_generator
+ gem_regex = /gem 'psych',\s+'~> 2.0', \s+platforms: :rbx/
+
+ assert_file "Gemfile" do |content|
+ if defined?(Rubinius)
+ assert_match(gem_regex, content)
+ else
+ assert_no_match(gem_regex, content)
+ end
+ end
+ end
+
protected
def action(*args, &block)

1 comment on commit 558f8aa

Contributor

splattael commented on 558f8aa Jul 24, 2014

👍 💚

Please sign in to comment.