carrierwave-scp 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +18 -0
- data/README.md +19 -0
- data/carrierwave-scp.gemspec +24 -0
- data/lib/carrierwave-scp.rb +16 -0
- data/lib/carrierwave-scp/version.rb +3 -0
- data/lib/carrierwave/storage/scp.rb +49 -0
- data/spec/carrierwave-scp_spec.rb +16 -0
- data/spec/carrierwave/storage/scp_spec.rb +25 -0
- data/spec/spec_helper.rb +63 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YTljODUxMTJjNjFhOGIzYTg2NTcyYmMwMjM0YmEzOTAwYzU4ZTRkYg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OTQ5NmYyMGM5YTlkNzUzNTY4NTM0ZjQwMGNhYmU4ZGM2YTU2OGExZA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OTQzM2RlZmE1ODQxYjNmZDQ0MDAyZWMwZjc0ODYzYjY3ZGU4YmUyYmI0MDg4
|
10
|
+
NDc3ZTNiMGFiMDNmZDY0Y2M1YjU4MjZiNjQxZTM2MjU0NDY4NmExNjVkNDIx
|
11
|
+
NjdmYzliYjdhMDQ4NGZhMDMyZTZlZmQzZGYxODM1NzVhMjZiNDI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZjI2ZDMwYTc1NDY5ZDNkNmEzOWM3YTY5Y2FlYTYzZmZlYmNkMTg5NDJmYmI2
|
14
|
+
NTEzMzdmZjJkYzEzNDA0OWI3MDgwMTNkZGExYThjZGNlYzU4NWEwZmE5ODQ3
|
15
|
+
NGI0YWVmOTRkYzMzZDQ1YzZhYzY0Y2U5N2I2OTRmZmM2ODIyMDI=
|
data/.gitignore
ADDED
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# CarrierWave SCP storage
|
2
|
+
|
3
|
+
Create the SCP storage alternative to upload files using [CarrierWave](https://github.com/jnicklas/carrierwave/)
|
4
|
+
|
5
|
+
## Gem
|
6
|
+
|
7
|
+
gem install carrierwave-scp
|
8
|
+
|
9
|
+
## Configuration
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
CarrierWave.configure do |config|
|
13
|
+
storage :scp
|
14
|
+
config.scp_host = "remote.host.com"
|
15
|
+
config.scp_user = "username"
|
16
|
+
config.scp_passwd = "password"
|
17
|
+
config.scp_folder = "/public_html/uploads"
|
18
|
+
end
|
19
|
+
```
|
@@ -0,0 +1,24 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
require "carrierwave-scp/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "carrierwave-scp"
|
7
|
+
s.version = CarrierwaveScp::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Rodrigo Batista da Silva"]
|
10
|
+
s.email = ["rbsilva.ti@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/rbsilva/carrierwave-scp"
|
12
|
+
s.summary = "SCP storage for CarrierWave."
|
13
|
+
s.description = "Add the storage option of SCP to the gem CarrierWave."
|
14
|
+
|
15
|
+
s.rubyforge_project = "carrierwave-scp"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
|
19
|
+
|
20
|
+
s.add_dependency "carrierwave"
|
21
|
+
s.add_dependency "net-scp"
|
22
|
+
|
23
|
+
s.add_development_dependency "rspec"
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'carrierwave'
|
2
|
+
require 'uri/open-scp'
|
3
|
+
require 'net/scp'
|
4
|
+
require 'carrierwave/storage/scp'
|
5
|
+
require 'carrierwave-scp/version'
|
6
|
+
|
7
|
+
class CarrierWave::Uploader::Base
|
8
|
+
add_config :scp_host
|
9
|
+
add_config :scp_user
|
10
|
+
add_config :scp_passwd
|
11
|
+
add_config :scp_folder
|
12
|
+
|
13
|
+
configure do |config|
|
14
|
+
config.storage_engines[:scp] = "CarrierWave::Storage::SCP"
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module CarrierWave
|
2
|
+
module Storage
|
3
|
+
class SCP < Abstract
|
4
|
+
|
5
|
+
def store!(file)
|
6
|
+
f = CarrierWave::Storage::SCP::File.new(uploader, self, uploader.store_path)
|
7
|
+
f.store(file)
|
8
|
+
f
|
9
|
+
end
|
10
|
+
|
11
|
+
def retrieve!(identifier)
|
12
|
+
CarrierWave::Storage::SCP::File.new(uploader, self, uploader.store_path(identifier))
|
13
|
+
end
|
14
|
+
|
15
|
+
class File
|
16
|
+
attr_reader :path
|
17
|
+
|
18
|
+
def extension
|
19
|
+
path.split('.').last
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(uploader, base, path)
|
23
|
+
@uploader, @base, @path = uploader, base, path
|
24
|
+
end
|
25
|
+
|
26
|
+
def read
|
27
|
+
file.read
|
28
|
+
end
|
29
|
+
|
30
|
+
def size
|
31
|
+
file.length
|
32
|
+
end
|
33
|
+
|
34
|
+
def store(new_file)
|
35
|
+
Net::SCP.upload!(@uploader.scp_host, @uploader.scp_user,
|
36
|
+
StringIO.new(new_file.read), "#{@uploader.scp_folder}/#{path}",
|
37
|
+
:password => @uploader.scp_passwd, :recursive => true)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def file
|
43
|
+
@file ||= open("scp://#{@uploader.scp_user}:#{@uploader.scp_passwd}@#{@uploader.scp_host}#{@uploader.scp_folder}/#{path}")
|
44
|
+
end
|
45
|
+
|
46
|
+
end #end File
|
47
|
+
end #end SCP
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CarrierWave::Uploader::Base do
|
4
|
+
it 'defines scp specific storage options' do
|
5
|
+
described_class.should respond_to(:scp_host)
|
6
|
+
described_class.should respond_to(:scp_user)
|
7
|
+
described_class.should respond_to(:scp_passwd)
|
8
|
+
described_class.should respond_to(:scp_folder)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'inserts scp as a known storage engine' do
|
12
|
+
described_class.configure do |config|
|
13
|
+
config.storage_engines.should have_key(:scp)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'carrierwave-scp'
|
3
|
+
|
4
|
+
class ScpUploader < CarrierWave::Uploader::Base
|
5
|
+
storage :scp
|
6
|
+
end
|
7
|
+
|
8
|
+
describe CarrierWave::Storage::SCP do
|
9
|
+
before do
|
10
|
+
CarrierWave.configure do |config|
|
11
|
+
config.scp_host = "localhost"
|
12
|
+
config.scp_user = "test"
|
13
|
+
config.scp_passwd = "test"
|
14
|
+
config.scp_folder = "/home/test"
|
15
|
+
end
|
16
|
+
|
17
|
+
@file = CarrierWave::SanitizedFile.new(file_path('test.jpg'))
|
18
|
+
ScpUploader.stub!(:store_path).and_return('uploads/test.jpg')
|
19
|
+
@storage = CarrierWave::Storage::SCP.new(ScpUploader)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "store the file" do
|
23
|
+
@stored = @storage.store!(@file)
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'rspec'
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
require 'carrierwave'
|
7
|
+
|
8
|
+
def file_path( *paths )
|
9
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', *paths))
|
10
|
+
end
|
11
|
+
|
12
|
+
def public_path( *paths )
|
13
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'public', *paths))
|
14
|
+
end
|
15
|
+
|
16
|
+
CarrierWave.root = public_path
|
17
|
+
|
18
|
+
module CarrierWave
|
19
|
+
module Test
|
20
|
+
module MockFiles
|
21
|
+
def stub_file(filename, mime_type=nil, fake_name=nil)
|
22
|
+
f = File.open(file_path(filename))
|
23
|
+
return f
|
24
|
+
end
|
25
|
+
|
26
|
+
def stub_tempfile(filename, mime_type=nil, fake_name=nil)
|
27
|
+
raise "#{path} file does not exist" unless File.exist?(file_path(filename))
|
28
|
+
|
29
|
+
t = Tempfile.new(filename)
|
30
|
+
FileUtils.copy_file(file_path(filename), t.path)
|
31
|
+
|
32
|
+
t.stub!(:local_path => "",
|
33
|
+
:original_filename => filename || fake_name,
|
34
|
+
:content_type => mime_type)
|
35
|
+
|
36
|
+
return t
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module I18nHelpers
|
41
|
+
def change_locale_and_store_translations(locale, translations, &block)
|
42
|
+
current_locale = I18n.locale
|
43
|
+
begin
|
44
|
+
I18n.backend.store_translations locale, translations
|
45
|
+
I18n.locale = locale
|
46
|
+
yield
|
47
|
+
ensure
|
48
|
+
I18n.reload!
|
49
|
+
I18n.locale = current_locale
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
RSpec.configure do |config|
|
57
|
+
config.include CarrierWave::Test::MockFiles
|
58
|
+
config.include CarrierWave::Test::I18nHelpers
|
59
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
60
|
+
config.filter_run :focus
|
61
|
+
config.order = 'random'
|
62
|
+
config.run_all_when_everything_filtered = true
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carrierwave-scp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rodrigo Batista da Silva
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: carrierwave
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: net-scp
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Add the storage option of SCP to the gem CarrierWave.
|
56
|
+
email:
|
57
|
+
- rbsilva.ti@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- README.md
|
64
|
+
- carrierwave-scp.gemspec
|
65
|
+
- lib/carrierwave-scp.rb
|
66
|
+
- lib/carrierwave-scp/version.rb
|
67
|
+
- lib/carrierwave/storage/scp.rb
|
68
|
+
- spec/carrierwave-scp_spec.rb
|
69
|
+
- spec/carrierwave/storage/scp_spec.rb
|
70
|
+
- spec/spec_helper.rb
|
71
|
+
homepage: https://github.com/rbsilva/carrierwave-scp
|
72
|
+
licenses: []
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project: carrierwave-scp
|
90
|
+
rubygems_version: 2.0.3
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: SCP storage for CarrierWave.
|
94
|
+
test_files: []
|