paperclip-fedora 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +14 -0
- data/Rakefile +1 -0
- data/config/paperclip_fedora.yml +14 -0
- data/lib/paperclip-fedora/version.rb +5 -0
- data/lib/paperclip-fedora.rb +95 -0
- data/paperclip-fedora.gemspec +23 -0
- metadata +75 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
paperclip-fedora
|
2
|
+
================
|
3
|
+
|
4
|
+
Paperclip-Fedora uses Rubydora to extend the storage options of Paperclip to use Fedora Commons.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
TODO: Tell how to install this thing!
|
9
|
+
|
10
|
+
## Copyright
|
11
|
+
|
12
|
+
Copyright (c) 2011 Jared Sartin. See LICENSE for
|
13
|
+
further details.
|
14
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
test:
|
2
|
+
user: 'fedoraAdmin'
|
3
|
+
password: 'fedoraAdmin'
|
4
|
+
host: 'http://localhost:8983/fedora'
|
5
|
+
|
6
|
+
development:
|
7
|
+
user: 'fedoraAdmin'
|
8
|
+
password: 'fedoraAdmin'
|
9
|
+
host: 'http://localhost:8983/fedora'
|
10
|
+
|
11
|
+
production:
|
12
|
+
user: 'fedoraAdmin'
|
13
|
+
password: 'fedoraAdmin'
|
14
|
+
host: 'http://localhost:8983/fedora'
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require "paperclip-fedora/version"
|
2
|
+
|
3
|
+
module Paperclip
|
4
|
+
module Storage
|
5
|
+
module Fedora
|
6
|
+
def self.extended(base)
|
7
|
+
require 'rubydora'
|
8
|
+
base.instance_eval do
|
9
|
+
if(!@options[:fedora_config])
|
10
|
+
@options[:fedora_config] = Rails.root.to_s + "/config/paperclip_fedora.yml"
|
11
|
+
end
|
12
|
+
|
13
|
+
@fedora_config = parse_config(@options[:fedora_config])
|
14
|
+
@url = @fedora_config[:host] + "/objects/upload\::id/datastreams/:style/content"
|
15
|
+
@path = "upload\::id"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def exists?(style=default_style)
|
20
|
+
exists_bool = !fedora_object.datastreams[style.to_s].new?
|
21
|
+
exists_bool
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_file(style=default_style)
|
25
|
+
return @queued_for_write[style.to_s] if @queued_for_write[style.to_s]
|
26
|
+
ds = fedora_object.datastreams[style.to_s]
|
27
|
+
file = Tempfile.new([ds.label, style.to_s])
|
28
|
+
file.binmode
|
29
|
+
file.write(ds.file)
|
30
|
+
file.rewind
|
31
|
+
return file
|
32
|
+
end
|
33
|
+
|
34
|
+
def flush_writes
|
35
|
+
@queued_for_write.each do |style, file|
|
36
|
+
ds = fedora_object.datastreams[style.to_s]
|
37
|
+
ds.controlGroup = 'M'
|
38
|
+
ds.file = file
|
39
|
+
ds.dsLabel = "TempFile"
|
40
|
+
ds.save
|
41
|
+
log("Added #{style} to #{@object_id}")
|
42
|
+
end
|
43
|
+
@queued_for_write = {}
|
44
|
+
end
|
45
|
+
|
46
|
+
def flush_deletes
|
47
|
+
@queued_for_delete.uniq!
|
48
|
+
@queued_for_delete.each do |path|
|
49
|
+
object = fedora.find(path)
|
50
|
+
object.delete if !object.new?
|
51
|
+
log("Deleted #{path}")
|
52
|
+
end
|
53
|
+
@queued_for_delete = []
|
54
|
+
end
|
55
|
+
|
56
|
+
def fedora
|
57
|
+
@@repo ||= Rubydora.connect url: @fedora_config[:host], user: @fedora_config[:user], password: @fedora_config[:password]
|
58
|
+
@@repo
|
59
|
+
end
|
60
|
+
|
61
|
+
def create_object
|
62
|
+
@object_id = path()
|
63
|
+
object = fedora.find(@object_id)
|
64
|
+
object.label = @object_id
|
65
|
+
saved_object = object.save
|
66
|
+
saved_object
|
67
|
+
end
|
68
|
+
|
69
|
+
def fedora_object
|
70
|
+
@fedora_object ||= create_object
|
71
|
+
end
|
72
|
+
|
73
|
+
def parse_config config
|
74
|
+
config = find_credentials(config).stringify_keys
|
75
|
+
(config[Rails.env] || config).symbolize_keys
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def find_credentials config
|
81
|
+
case config
|
82
|
+
when File
|
83
|
+
YAML.load_file(config.path)
|
84
|
+
when String
|
85
|
+
YAML.load_file(config)
|
86
|
+
when Hash
|
87
|
+
config
|
88
|
+
else
|
89
|
+
raise ArgumentError, "Configuration settings are not a path, file, or hash."
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "paperclip-fedora/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "paperclip-fedora"
|
7
|
+
s.version = Paperclip::Fedora::VERSION
|
8
|
+
s.authors = ["Jared Sartin"]
|
9
|
+
s.email = ["jaredsartin@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/JaredSartin/paperclip-fedora"
|
11
|
+
s.summary = %q{Fedora Commons storage support for paperclip file attachment}
|
12
|
+
s.description = %q{Adds Fedora Commons storage support for the Paperclip gem.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "paperclip-fedora"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_runtime_dependency "paperclip"
|
22
|
+
s.add_runtime_dependency "rubydora"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paperclip-fedora
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jared Sartin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-09-14 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: paperclip
|
16
|
+
requirement: &2152403360 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2152403360
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rubydora
|
27
|
+
requirement: &2152402940 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2152402940
|
36
|
+
description: Adds Fedora Commons storage support for the Paperclip gem.
|
37
|
+
email:
|
38
|
+
- jaredsartin@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- README.md
|
46
|
+
- Rakefile
|
47
|
+
- config/paperclip_fedora.yml
|
48
|
+
- lib/paperclip-fedora.rb
|
49
|
+
- lib/paperclip-fedora/version.rb
|
50
|
+
- paperclip-fedora.gemspec
|
51
|
+
homepage: https://github.com/JaredSartin/paperclip-fedora
|
52
|
+
licenses: []
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project: paperclip-fedora
|
71
|
+
rubygems_version: 1.8.10
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Fedora Commons storage support for paperclip file attachment
|
75
|
+
test_files: []
|