carriercouch 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README +1 -0
- data/Rakefile +2 -0
- data/carriercouch.gemspec +28 -0
- data/lib/carrierwave.rb +14 -0
- data/lib/carrierwave/orm/couchrest_model.rb +39 -0
- data/lib/carrierwave/storage/couch.rb +149 -0
- data/lib/carrierwave/uploader/configuration.rb +27 -0
- data/lib/version.rb +3 -0
- metadata +131 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
CarrierCouch Documentation ..... coming
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "carriercouch"
|
7
|
+
s.version = Carriercouch::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Shenouda Bertel"]
|
10
|
+
s.email = ["sbertel@arpuplus.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Carrierwave Uploader for CouchDB with CouchrestModel}
|
13
|
+
s.description = %q{Carrierwave Uploader for CouchDB with CouchrestModel}
|
14
|
+
|
15
|
+
s.rubyforge_project = "carriercouch"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency "rails", ["~> 3.0.5"]
|
23
|
+
s.add_development_dependency "rspec"
|
24
|
+
s.add_development_dependency "mini_magick", ["~> 2.3"]
|
25
|
+
s.add_development_dependency "carrierwave"
|
26
|
+
s.add_development_dependency "activemodel"
|
27
|
+
s.add_development_dependency "couchrest_model"
|
28
|
+
end
|
data/lib/carrierwave.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'carrierwave'
|
2
|
+
require 'carrierwave/orm/couchrest_model'
|
3
|
+
require 'carrierwave/storage/couch'
|
4
|
+
#require 'carrierwave/uploader/configuration'
|
5
|
+
|
6
|
+
#module CarrierWave
|
7
|
+
# module Storage
|
8
|
+
# autoload :Couch, 'carrierwave/storage/couch'
|
9
|
+
# end
|
10
|
+
#end
|
11
|
+
|
12
|
+
CarrierWave.configure do |config|
|
13
|
+
config.storage_engines[:couch] = 'CarrierWave::Storage::Couch'
|
14
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'couchrest_model'
|
4
|
+
require 'carrierwave/validations/active_model'
|
5
|
+
|
6
|
+
module CarrierWave
|
7
|
+
module CouchrestModel
|
8
|
+
include CarrierWave::Mount
|
9
|
+
##
|
10
|
+
# See +CarrierWave::Mount#mount_uploader+ for documentation
|
11
|
+
#
|
12
|
+
def mount_uploader(column, uploader, options={}, &block)
|
13
|
+
options[:mount_on] ||= "#{column}_filename"
|
14
|
+
property options[:mount_on]
|
15
|
+
|
16
|
+
super
|
17
|
+
|
18
|
+
alias_method :read_uploader, :read_attribute
|
19
|
+
alias_method :write_uploader, :write_attribute
|
20
|
+
|
21
|
+
include CarrierWave::Validations::ActiveModel
|
22
|
+
|
23
|
+
validates_integrity_of column if uploader_option(column.to_sym, :validate_integrity)
|
24
|
+
validates_processing_of column if uploader_option(column.to_sym, :validate_processing)
|
25
|
+
|
26
|
+
after_save "store_#{column}!".to_sym
|
27
|
+
before_save "write_#{column}_identifier".to_sym
|
28
|
+
after_destroy "remove_#{column}!".to_sym
|
29
|
+
end
|
30
|
+
end # CouchrestModel
|
31
|
+
end # CarrierWave
|
32
|
+
|
33
|
+
module CouchRest
|
34
|
+
module Model
|
35
|
+
class Base
|
36
|
+
extend ::CarrierWave::CouchrestModel
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'couchrest'
|
4
|
+
require 'couchrest_model'
|
5
|
+
|
6
|
+
module CarrierWave
|
7
|
+
module Storage
|
8
|
+
|
9
|
+
##
|
10
|
+
# Couch storage stores file to the Couchdb (surprising, no?). There's really not much
|
11
|
+
# to it.
|
12
|
+
#
|
13
|
+
# Creating a connection looks something like this:
|
14
|
+
#
|
15
|
+
# CarrierWave.configure do |config|
|
16
|
+
# config.storage = :couch
|
17
|
+
# config.couch_host = "your-host.com"
|
18
|
+
# config.couch_port = "5984"
|
19
|
+
# config.couch_database = "your_dbs_app_name"
|
20
|
+
# config.couch_username = "user"
|
21
|
+
# config.couch_password = "verysecret"
|
22
|
+
# config.couch_access_url = "/images"
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# In the above example your documents url will look like:
|
26
|
+
#
|
27
|
+
# http://your-app.com:5984/:database/:document_id/:document-identifier-here
|
28
|
+
#
|
29
|
+
# When you already have a CouchDB connection object :
|
30
|
+
#
|
31
|
+
# CarrierWave.configure do |config|
|
32
|
+
# config.storage = :couchdb
|
33
|
+
# config.couch_connection = model.use_database
|
34
|
+
# config.couch_access_url = "/images"
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
class Couch < Abstract
|
38
|
+
class File
|
39
|
+
def initialize(uploader, path)
|
40
|
+
@uploader = uploader
|
41
|
+
@path = path
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Returns the current path of the file on S3
|
46
|
+
#
|
47
|
+
# === Returns
|
48
|
+
#
|
49
|
+
# [String] A path
|
50
|
+
#
|
51
|
+
def path
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Reads the contents of the file from S3
|
57
|
+
#
|
58
|
+
# === Returns
|
59
|
+
#
|
60
|
+
# [String] contents of the file
|
61
|
+
#
|
62
|
+
def read
|
63
|
+
result = model.fetch_attachment(@path)
|
64
|
+
@headers = result.headers
|
65
|
+
result.body
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# Remove the file from Amazon S3
|
70
|
+
#
|
71
|
+
def delete
|
72
|
+
model.delete_attachment(@path)
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Returns the url on CouchDB
|
77
|
+
#
|
78
|
+
# === Returns
|
79
|
+
#
|
80
|
+
# [String] content's url
|
81
|
+
#
|
82
|
+
def url
|
83
|
+
@uploader.couch_connection + "/" + @uploader.couch_database + "/" + model.id + "/" + @path
|
84
|
+
end
|
85
|
+
|
86
|
+
def store(file)
|
87
|
+
content_type ||= file.content_type # this might cause problems if content type changes between read and upload (unlikely)
|
88
|
+
model.put_attachment(file.filename, file.read, {:content_type => content_type})
|
89
|
+
end
|
90
|
+
|
91
|
+
def content_type
|
92
|
+
headers["Content-Type"]
|
93
|
+
end
|
94
|
+
|
95
|
+
def content_type=(type)
|
96
|
+
headers["Content-Type"] = type
|
97
|
+
end
|
98
|
+
|
99
|
+
def size
|
100
|
+
headers['Content-Length'].to_i
|
101
|
+
end
|
102
|
+
|
103
|
+
# Headers returned from file retrieval
|
104
|
+
def headers
|
105
|
+
@headers
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def model
|
111
|
+
@uploader.model
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
##
|
116
|
+
# Move the file to the uploader's store path.
|
117
|
+
#
|
118
|
+
# === Parameters
|
119
|
+
#
|
120
|
+
# [file (CarrierWave::Storage::Couch::File)] the file to store
|
121
|
+
#
|
122
|
+
# === Returns
|
123
|
+
#
|
124
|
+
# [CarrierWave::Storage::Couch::File] a couch file
|
125
|
+
#
|
126
|
+
def store!(file)
|
127
|
+
f = CarrierWave::Storage::Couch::File.new(uploader, '')
|
128
|
+
f.store(file)
|
129
|
+
f
|
130
|
+
end
|
131
|
+
|
132
|
+
##
|
133
|
+
# Retrieve the file from its store path
|
134
|
+
#
|
135
|
+
# === Parameters
|
136
|
+
#
|
137
|
+
# [identifier (String)] the filename of the file
|
138
|
+
#
|
139
|
+
# === Returns
|
140
|
+
#
|
141
|
+
# [CarrierWave::Storage::Couch::File] a couch file
|
142
|
+
#
|
143
|
+
def retrieve!(identifier)
|
144
|
+
CarrierWave::Storage::Couch::File.new(uploader, identifier)
|
145
|
+
end
|
146
|
+
|
147
|
+
end # Couch
|
148
|
+
end # Storage
|
149
|
+
end # CarrierWave
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'carrierwave'
|
2
|
+
|
3
|
+
module CarrierWave
|
4
|
+
module Uploader
|
5
|
+
module Configuration
|
6
|
+
|
7
|
+
included do
|
8
|
+
add_config :couch_host
|
9
|
+
add_config :couch_port
|
10
|
+
add_config :couch_database
|
11
|
+
add_config :couch_username
|
12
|
+
add_config :couch_password
|
13
|
+
add_config :couch_connection
|
14
|
+
add_config :couch_access_url
|
15
|
+
|
16
|
+
configure do |config|
|
17
|
+
config.permissions = 0644
|
18
|
+
config.storage_engines = {
|
19
|
+
:couch => "CarrierWave::Storage::Couch"
|
20
|
+
}
|
21
|
+
config.couch_host = 'localhost'
|
22
|
+
config.couch_port = 5984
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carriercouch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Shenouda Bertel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-03-03 00:00:00 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rails
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 3.0.5
|
25
|
+
type: :development
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: mini_magick
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "2.3"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: carrierwave
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: activemodel
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: couchrest_model
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id006
|
82
|
+
description: Carrierwave Uploader for CouchDB with CouchrestModel
|
83
|
+
email:
|
84
|
+
- sbertel@arpuplus.com
|
85
|
+
executables: []
|
86
|
+
|
87
|
+
extensions: []
|
88
|
+
|
89
|
+
extra_rdoc_files: []
|
90
|
+
|
91
|
+
files:
|
92
|
+
- .gitignore
|
93
|
+
- Gemfile
|
94
|
+
- README
|
95
|
+
- Rakefile
|
96
|
+
- carriercouch.gemspec
|
97
|
+
- lib/carrierwave.rb
|
98
|
+
- lib/carrierwave/orm/couchrest_model.rb
|
99
|
+
- lib/carrierwave/storage/couch.rb
|
100
|
+
- lib/carrierwave/uploader/configuration.rb
|
101
|
+
- lib/version.rb
|
102
|
+
has_rdoc: true
|
103
|
+
homepage: ""
|
104
|
+
licenses: []
|
105
|
+
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: "0"
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: "0"
|
123
|
+
requirements: []
|
124
|
+
|
125
|
+
rubyforge_project: carriercouch
|
126
|
+
rubygems_version: 1.6.0
|
127
|
+
signing_key:
|
128
|
+
specification_version: 3
|
129
|
+
summary: Carrierwave Uploader for CouchDB with CouchrestModel
|
130
|
+
test_files: []
|
131
|
+
|