Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Providing a YAMLAdaptor for Psych dependency #128

Merged
merged 1 commit into from
Jun 27, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/active_fedora/file_configurator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'erb'
require 'psych'
require 'active_fedora/yaml_adaptor'

module ActiveFedora
class FileConfigurator
Expand Down Expand Up @@ -110,7 +110,7 @@ def load_fedora_config
end

begin
fedora_yml = Psych.load(config_erb)
fedora_yml = YAMLAdaptor.load(config_erb)
rescue StandardError => e
raise("fedora.yml was found, but could not be parsed.\n")
end
Expand All @@ -133,7 +133,7 @@ def load_solr_config
end

begin
solr_yml = Psych.load(config_erb)
solr_yml = YAMLAdaptor.load(config_erb)
rescue StandardError => e
raise("solr.yml was found, but could not be parsed.\n")
end
Expand Down Expand Up @@ -209,7 +209,7 @@ def check_fedora_path_for_solr

def predicate_config
@predicate_config_path ||= build_predicate_config_path(File.dirname(self.path))
Psych.load(File.open(@predicate_config_path)) if File.exist?(@predicate_config_path)
YAMLAdaptor.load(File.open(@predicate_config_path)) if File.exist?(@predicate_config_path)
end

protected
Expand All @@ -227,7 +227,7 @@ def build_predicate_config_path(config_path=nil)
end

def valid_predicate_mapping?(testfile)
mapping = Psych.load(File.open(testfile))
mapping = YAMLAdaptor.load(File.open(testfile))
return false unless mapping.has_key?(:default_namespace) && mapping[:default_namespace].is_a?(String)
return false unless mapping.has_key?(:predicate_mapping) && mapping[:predicate_mapping].is_a?(Hash)
true
Expand Down
12 changes: 12 additions & 0 deletions lib/active_fedora/yaml_adaptor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
begin
require 'psych'
YAMLAdaptor = Psych
rescue LoadError
$stderr.puts "*"*80
$stderr.puts "WARNING: Unable to load Psych, falling back to YAML for parser."
$stderr.puts " YAML will be removed in ActiveFedora 7.0.0."
$stderr.puts " YAMLAdaptor will be removed in ActiveFedora 7.0.0, and replaced with Psych"
$stderr.puts "*"*80
require 'yaml'
YAMLAdaptor = YAML
end
2 changes: 1 addition & 1 deletion spec/config_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ def mock_yaml(hash, path)
mock_file = mock(path.split("/")[-1])
File.stub(:exist?).with(path).and_return(true)
File.stub(:open).with(path).and_return(mock_file)
YAML.stub(:load).and_return(hash)
YAMLAdaptor.stub(:load).and_return(hash)
end

def default_predicate_mapping_file
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/code_configurator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def init(options = {})
end

it "should initialize from code" do
YAML.should_receive(:load).never
YAMLAdaptor.should_receive(:load).never
File.should_receive(:exists?).never
File.should_receive(:read).never
File.should_receive(:open).never
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

describe ActiveFedora::Config do
describe "with a single fedora instance" do
conf = Psych.load(File.read('spec/fixtures/rails_root/config/fedora.yml'))['test']
conf = YAMLAdaptor.load(File.read('spec/fixtures/rails_root/config/fedora.yml'))['test']
subject { ActiveFedora::Config.new(conf) }
its(:credentials) { should == {:url => 'http://testhost.com:8983/fedora', :user=> 'fedoraAdmin', :password=> 'fedoraAdmin'}}
it { should_not be_sharded }
end
describe "with several fedora shards" do
conf = Psych.load(File.read('spec/fixtures/sharded_fedora.yml'))['test']
conf = YAMLAdaptor.load(File.read('spec/fixtures/sharded_fedora.yml'))['test']
subject { ActiveFedora::Config.new(conf) }
its(:credentials) { should == [{:url => 'http://127.0.0.1:8983/fedora1', :user=> 'fedoraAdmin', :password=> 'fedoraAdmin'},
{:url => 'http://127.0.0.1:8983/fedora2', :user=> 'fedoraAdmin', :password=> 'fedoraAdmin'},
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/file_configurator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@
subject.instance_variable_set :@config_loaded, nil
end
it "should return the default mapping if it has not been initialized" do
subject.predicate_config().should == YAML.load(File.read(default_predicate_mapping_file))
subject.predicate_config().should == YAMLAdaptor.load(File.read(default_predicate_mapping_file))
end
end

Expand Down