lib/paperclip-fedora.rb in paperclip-fedora-0.1.0 vs lib/paperclip-fedora.rb in paperclip-fedora-0.2.0
- old
+ new
@@ -1,15 +1,18 @@
require "paperclip-fedora/version"
+require "paperclip-fedora/railtie" if Rails.version >= "3.0"
+require "FileUtils" unless defined?(FileUtils)
module Paperclip
module Storage
module Fedora
+ extend self
def self.extended(base)
require 'rubydora'
base.instance_eval do
if(!@options[:fedora_config])
- @options[:fedora_config] = Rails.root.to_s + "/config/paperclip_fedora.yml"
+ @options[:fedora_config] = config_file
end
@fedora_config = parse_config(@options[:fedora_config])
@url = @fedora_config[:host] + "/objects/upload\::id/datastreams/:style/content"
@path = "upload\::id"
@@ -36,11 +39,11 @@
ds = fedora_object.datastreams[style.to_s]
ds.controlGroup = 'M'
ds.file = file
ds.dsLabel = "TempFile"
ds.save
- log("Added #{style} to #{@object_id}")
+ log("Added #{style} datastream to #{@object_id}")
end
@queued_for_write = {}
end
def flush_deletes
@@ -71,9 +74,21 @@
end
def parse_config config
config = find_credentials(config).stringify_keys
(config[Rails.env] || config).symbolize_keys
+ end
+
+ def setup!
+ FileUtils.cp(File.dirname(__FILE__) + "/../config/paperclip_fedora.yml", config_file) unless config?
+ end
+
+ def config_file
+ Rails.root.join("config", "paperclip_fedora.yml").to_s
+ end
+
+ def config?
+ File.file? config_file
end
private
def find_credentials config