paperclip-elvfs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in paperclip-elvfs.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Dmitry Lihachev
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Paperclip::Elvfs
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'paperclip-elvfs'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install paperclip-elvfs
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # add url field into migration
2
+ Paperclip::Schema::COLUMNS.merge!(:url => :text)
3
+
4
+ # default settings
5
+ Paperclip::Attachment.default_options[:path] = ':app_name/:class/:attachment/:date/:id/:filename'
6
+ Paperclip::Attachment.default_options[:url] = :file_url
7
+ Paperclip::Attachment.default_options[:escape_url] = false
8
+
9
+ # TODO: remove this warn when paperclip 3.3.2 will be released
10
+ class Paperclip::Attachment
11
+ def url_with_unescape(style_name = default_style, options = {})
12
+ ActiveSupport::Deprecation.warn "Remove this warning when paperclip 3.3.2 will be released"
13
+ options[:escape] = false
14
+ url_without_unescape(style_name, options)
15
+ end
16
+
17
+ alias_method_chain :url, :unescape
18
+ end
19
+
20
+ # our interpolators
21
+ Paperclip.interpolates :app_name do |attachment, style|
22
+ Rails.application.railtie_name.sub /_application$/, ''
23
+ end
24
+
25
+ Paperclip.interpolates :date do |attachment, style|
26
+ Date.today.strftime '%Y/%m/%d'
27
+ end
@@ -0,0 +1,5 @@
1
+ module Paperclip
2
+ module Elvfs
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ require 'paperclip'
2
+ require 'paperclip/elvfs/settings'
3
+ require 'paperclip/elvfs/version'
4
+ require 'paperclip/storage/elvfs'
5
+ require 'curb'
6
+
7
+
8
+ module Paperclip
9
+ module Elvfs
10
+ end
11
+ end
@@ -0,0 +1,68 @@
1
+ require 'open-uri'
2
+
3
+ module Paperclip
4
+ module Storage
5
+ module Elvfs
6
+ def self.extended base
7
+ end
8
+
9
+ def exists?(style_name = default_style)
10
+ if original_filename
11
+ !!file_json(path(style_name))
12
+ else
13
+ false
14
+ end
15
+ end
16
+
17
+ def flush_writes #:nodoc:
18
+ @queued_for_write.each do |style_name, file|
19
+ delete_entry(path(style_name)) if exists?(style_name)
20
+ upload_file(path(style_name), file)
21
+ end
22
+
23
+ after_flush_writes # allows attachment to clean up temp files
24
+
25
+ @queued_for_write = {}
26
+ end
27
+
28
+ def flush_deletes #:nodoc:
29
+ @queued_for_delete.each do |path|
30
+ log("deleting #{path}")
31
+ delete_entry(File.dirname(path))
32
+ end
33
+ @queued_for_delete = []
34
+ end
35
+
36
+ private
37
+ def directory_json(path)
38
+ JSON.parse(open(storage_url("#{File.dirname(path)}?cmd=open&init=true")).read)
39
+ end
40
+
41
+ def file_json(path)
42
+ directory_json(path)['files'].select{|file| file['name'] == File.basename(path).gsub(/\+/, ' ')}.first
43
+ end
44
+
45
+ def directory_target(path)
46
+ directory_json(path)['cwd']['hash']
47
+ end
48
+
49
+ def delete_entry(path)
50
+ if file_hash = file_json(path)
51
+ open(storage_url("#{File.dirname(path)}?cmd=rm&targets[]=#{file_hash['hash']}"))
52
+ end
53
+ end
54
+
55
+ def upload_file(path, file)
56
+ curl = Curl::Easy.new(storage_url("#{File.dirname(path)}?cmd=upload&target=#{directory_target(path)}")) do |curl|
57
+ curl.multipart_form_post = true
58
+ curl.on_success{|response| instance.update_column "#{name}_url", JSON.parse(response.body_str)['added'].first['url'] }
59
+ end
60
+ curl.http_post(Curl::PostField.file('upload[]', file.path, File.basename(path)))
61
+ end
62
+
63
+ def storage_url(path='')
64
+ "#{options[:elvfs_url]}/api/el_finder/v2/#{path}"
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'paperclip/elvfs/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "paperclip-elvfs"
8
+ gem.version = Paperclip::Elvfs::VERSION
9
+ gem.authors = ["OpenTeam"]
10
+ gem.email = ["developers@openteam.ru"]
11
+ gem.description = %q{Paperclip ElVFS adapter}
12
+ gem.summary = %q{Paperclip ElVFS adapter}
13
+ gem.homepage = "http://github.com/openteam/paperclip-elvfs"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.license = "MIT"
20
+
21
+ gem.add_dependency 'curb'
22
+ gem.add_dependency 'paperclip'
23
+
24
+ gem.add_development_dependency 'rake'
25
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paperclip-elvfs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - OpenTeam
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: curb
16
+ requirement: !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: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: paperclip
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Paperclip ElVFS adapter
63
+ email:
64
+ - developers@openteam.ru
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - lib/paperclip/elvfs.rb
75
+ - lib/paperclip/elvfs/settings.rb
76
+ - lib/paperclip/elvfs/version.rb
77
+ - lib/paperclip/storage/elvfs.rb
78
+ - paperclip-elvfs.gemspec
79
+ homepage: http://github.com/openteam/paperclip-elvfs
80
+ licenses:
81
+ - MIT
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ segments:
93
+ - 0
94
+ hash: -390824516123300352
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ segments:
102
+ - 0
103
+ hash: -390824516123300352
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.24
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Paperclip ElVFS adapter
110
+ test_files: []