diff --git a/Gemfile b/Gemfile index fefa2cf..0577e70 100644 --- a/Gemfile +++ b/Gemfile @@ -9,5 +9,6 @@ group :development, :test do gem 'coveralls', require: false, platforms: [:mri] gem 'activerecord', '~> 4.1' + gem 'nokogiri', '~> 1.6' gem 'ox', '>= 2.1.2', platforms: [:mri, :rbx] end diff --git a/README.md b/README.md index 50a66b7..a357acd 100644 --- a/README.md +++ b/README.md @@ -28,30 +28,20 @@ $ bundle ## Usage -To use **Nokogiri** as a SAX handler: +SAX Machine can use either `nokogiri` or `ox` as XML SAX handler. -```ruby -require 'sax-machine' -``` - -To use **Ox** as a SAX handler: - -Add this line to your application's Gemfile: +To use **Nokogiri** add this line to your Gemfile: ```ruby -gem 'ox', '>= 2.1.2' +gem 'nokogiri', '~> 1.6' ``` -Tell SAXMachine to use Ox: +To use **Ox** add this line to your Gemfile: ```ruby -require 'sax-machine' -SAXMachine.handler = :ox +gem 'ox', '>= 2.1.2' ``` -Please note that this operation is not thread-safe, so it's better to define -handler at initialization stage and do not change it during runtime. - ## Examples Include `SAXMachine` in any class and define properties to parse: diff --git a/lib/sax-machine.rb b/lib/sax-machine.rb index 64fa824..5bfa244 100644 --- a/lib/sax-machine.rb +++ b/lib/sax-machine.rb @@ -14,4 +14,8 @@ def self.handler=(handler) end end -SAXMachine.handler = :nokogiri +begin + SAXMachine.handler = :ox +rescue LoadError + SAXMachine.handler = :nokogiri +end diff --git a/sax-machine.gemspec b/sax-machine.gemspec index 6d603f6..44e4f67 100644 --- a/sax-machine.gemspec +++ b/sax-machine.gemspec @@ -16,6 +16,5 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.platform = Gem::Platform::RUBY - s.add_dependency "nokogiri", "~> 1.6.0" s.add_development_dependency "rspec", "~> 3.0" end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 546a9d0..91d44dc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,9 +14,7 @@ end require File.expand_path(File.dirname(__FILE__) + '/../lib/sax-machine') -if ENV['HANDLER'] == 'ox' - SAXMachine.handler = :ox -end +SAXMachine.handler = ENV['HANDLER'].to_sym RSpec.configure do |config| config.run_all_when_everything_filtered = true