Skip to content

Commit

Permalink
map Concurrent::Hash to ThreadSafe::Cache in Ruby 1.8.7
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Jul 31, 2018
1 parent b87d6e3 commit e6d2d7a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
31 changes: 18 additions & 13 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,30 @@ source 'https://rubygems.org'
gemspec

group :development do
if (ruby_version = Gem::Version.new RUBY_VERSION) < (Gem::Version.new '2.1.0')
if ruby_version < (Gem::Version.new '2.0.0')
gem 'haml', '~> 4.0.0'
if ruby_version < (Gem::Version.new '1.9.3')
gem 'cucumber', '~> 1.3.0'
gem 'nokogiri', '~> 1.5.0'
gem 'slim', '~> 2.1.0'
gem 'tilt', '2.0.7'
ruby_version = Gem::Version.new RUBY_VERSION
gem 'concurrent-ruby', '~> 1.0.0' unless ruby_version < (Gem::Version.new '1.9.3')
if ruby_version < (Gem::Version.new '2.2.0')
if ruby_version < (Gem::Version.new '2.1.0')
if ruby_version < (Gem::Version.new '2.0.0')
gem 'haml', '~> 4.0.0'
if ruby_version < (Gem::Version.new '1.9.3')
gem 'cucumber', '~> 1.3.0'
gem 'nokogiri', '~> 1.5.0'
gem 'slim', '~> 2.1.0'
gem 'thread_safe', '0.3.6'
gem 'tilt', '2.0.7'
else
gem 'nokogiri', '~> 1.6.0'
gem 'slim', '<= 3.0.7'
end
else
gem 'nokogiri', '~> 1.6.0'
gem 'slim', '<= 3.0.7'
end
else
gem 'nokogiri', '~> 1.6.0'
gem 'nokogiri', '~> 1.7.0' if Gem::Platform.local =~ 'x86-mingw32' || Gem::Platform.local =~ 'x64-mingw32'
gem 'racc', '~> 1.4.0' if RUBY_VERSION == '2.1.0' && RUBY_ENGINE == 'rbx'
end
elsif ruby_version < (Gem::Version.new '2.2.0')
gem 'nokogiri', '~> 1.7.0' if Gem::Platform.local =~ 'x86-mingw32' || Gem::Platform.local =~ 'x64-mingw32'
end
gem 'racc', '~> 1.4.0' if RUBY_VERSION == '2.1.0' && RUBY_ENGINE == 'rbx'
end

group :doc do
Expand Down
3 changes: 2 additions & 1 deletion asciidoctor.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rspec-expectations', '~> 2.14.0'
# slim is needed for testing custom templates
s.add_development_dependency 'slim', '~> 3.0.0'
s.add_development_dependency 'concurrent-ruby', '~> 1.0.5'
# concurrent-ruby is defined in Gemfile due to enforcement of minimum required Ruby version
#s.add_development_dependency 'concurrent-ruby', '~> 1.0.0'
# tilt is needed for testing custom templates
s.add_development_dependency 'tilt', '~> 2.0.0'
s.add_development_dependency 'minitest', '~> 5.3.0'
Expand Down
10 changes: 7 additions & 3 deletions lib/asciidoctor/converter/template.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
autoload :Concurrent, 'concurrent'

# encoding: UTF-8
module Asciidoctor
# A {Converter} implementation that uses templates composed in template
Expand Down Expand Up @@ -36,7 +34,13 @@ class Converter::TemplateConverter < Converter::Base
}

begin
# triggers autoload of concurrent
unless defined? ::Concurrent::Hash
if ::RUBY_MIN_VERSION_1_9
require 'concurrent/hash'
else
require 'asciidoctor/core_ext/1.8.7/concurrent/hash'
end
end
@caches = { :scans => ::Concurrent::Hash.new, :templates => ::Concurrent::Hash.new }
rescue ::LoadError
@caches = { :scans => {}, :templates => {} }
Expand Down
5 changes: 5 additions & 0 deletions lib/asciidoctor/core_ext/1.8.7/concurrent/hash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
autoload :ThreadSafe, 'thread_safe'

module Concurrent
Hash = ::ThreadSafe::Cache
end

0 comments on commit e6d2d7a

Please sign in to comment.