Skip to content

Commit

Permalink
Make nokogiri dependency optional
Browse files Browse the repository at this point in the history
  • Loading branch information
krasnoukhov committed Aug 5, 2014
1 parent 4e21ad8 commit 20d35ac
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,26 @@ $ bundle

## Usage

To use **Nokogiri** as a SAX handler:
SAX Machine can use either `nokogiri` or `ox` as XML SAX handler.

To use **Nokogiri** add this line to your Gemfile:

```ruby
require 'sax-machine'
gem 'nokogiri', '~> 1.6'
```

To use **Ox** as a SAX handler:

Add this line to your application's Gemfile:
To use **Ox** add this line to your Gemfile:

```ruby
gem 'ox', '>= 2.1.2'
```

Tell SAXMachine to use Ox:
You can also specify which handler to use manually, like this:

```ruby
require 'sax-machine'
SAXMachine.handler = :ox
SAXMachine.handler = :nokogiri
```

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:
Expand Down
6 changes: 5 additions & 1 deletion lib/sax-machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ def self.handler=(handler)
end
end

SAXMachine.handler = :nokogiri
begin
SAXMachine.handler = :ox
rescue LoadError
SAXMachine.handler = :nokogiri
end
1 change: 0 additions & 1 deletion sax-machine.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 1 addition & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 20d35ac

Please sign in to comment.