Skip to content

Commit

Permalink
prefer JSON, but fall back to YAML if JSON isn't available
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie Somerville committed Dec 3, 2013
1 parent 10cadb8 commit 27c9774
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/linguist/samples.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
require 'json'
begin
require 'json'
rescue LoadError
require 'yaml'
end

require 'linguist/md5'
require 'linguist/classifier'
Expand All @@ -14,7 +18,8 @@ module Samples

# Hash of serialized samples object
if File.exist?(PATH)
DATA = JSON.load(File.read(PATH))
serializer = defined?(JSON) ? JSON : YAML
DATA = serializer.load(File.read(PATH))
end

# Public: Iterate over each sample.
Expand Down

0 comments on commit 27c9774

Please sign in to comment.