paperclip-tt 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
File without changes
data/LICENSE ADDED
File without changes
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # TokyoTyrant
2
+
3
+ This gem extends [Paperclip](https://github.com/thoughtbot/paperclip) with
4
+ TokyoTyrant storage.
5
+
6
+ ## Installation
7
+
8
+ Put it in your `Gemfile`:
9
+
10
+ ```ruby
11
+ gem "paperclip-tt"
12
+ ```
13
+
14
+ And run `bundle install`.
@@ -0,0 +1,2 @@
1
+ require "paperclip"
2
+ require "paperclip/tokyo_tyrant"
@@ -0,0 +1,62 @@
1
+ module Paperclip
2
+ module Storage
3
+ module TokyoTyrant
4
+ def self.extended base
5
+ begin
6
+ require 'rufus/tokyo/tyrant'
7
+ rescue LoadError => e
8
+ e.message << " (You may need to install the rufus-tokyo gem)"
9
+ raise e
10
+ end
11
+ end
12
+
13
+ def exists?(style_name = default_style)
14
+ if original_filename
15
+ tt_object(style_name)
16
+ else
17
+ false
18
+ end
19
+ end
20
+
21
+ def tt_bucket
22
+ @tt_bucket ||= Rufus::Tokyo::Tyrant.new(@options[:tt_host], @options[:tt_port])
23
+ end
24
+
25
+ def tt_object style_name = default_style
26
+ tt_bucket[path(style_name).sub(%r{^/},'')]
27
+ end
28
+
29
+ def flush_writes #:nodoc:
30
+ @queued_for_write.each do |style_name, file|
31
+ tt_bucket[path(style_name).sub(%r{^/},'')] = file.read
32
+ end
33
+
34
+ after_flush_writes # allows attachment to clean up temp files
35
+
36
+ @queued_for_write = {}
37
+ end
38
+
39
+ def flush_deletes #:nodoc:
40
+ @queued_for_delete.each do |path|
41
+ begin
42
+ log("deleting #{path}")
43
+ tt_bucket.delete(path)
44
+ rescue Errno::ENOENT => e
45
+ # ignore file-not-found, let everything else pass
46
+ end
47
+ end
48
+ @queued_for_delete = []
49
+ end
50
+
51
+ def copy_to_local_file(style, local_dest_path)
52
+ log("copying #{path(style)} to local file #{local_dest_path}")
53
+ local_file = ::File.open(local_dest_path, 'wb')
54
+ tt_bucket[path(style).sub(%r{^/},'')] = local_file.read
55
+ rescue
56
+ warn("cannot copy #{path(style)} to local file #{local_dest_path}")
57
+ false
58
+ end
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1 @@
1
+ require "paperclip/storage/tokyo_tyrant"
@@ -0,0 +1,62 @@
1
+ module Paperclip
2
+ module Storage
3
+ module TokyoTyrant
4
+ def self.extended base
5
+ begin
6
+ require 'rufus/tokyo/tyrant'
7
+ rescue LoadError => e
8
+ e.message << " (You may need to install the rufus-tokyo gem)"
9
+ raise e
10
+ end
11
+ end
12
+
13
+ def exists?(style_name = default_style)
14
+ if original_filename
15
+ tt_object(style_name)
16
+ else
17
+ false
18
+ end
19
+ end
20
+
21
+ def tt_bucket
22
+ @tt_bucket ||= Rufus::Tokyo::Tyrant.new(@options[:tt_host], @options[:tt_port])
23
+ end
24
+
25
+ def tt_object style_name = default_style
26
+ tt_bucket[path(style_name).sub(%r{^/},'')]
27
+ end
28
+
29
+ def flush_writes #:nodoc:
30
+ @queued_for_write.each do |style_name, file|
31
+ tt_bucket[path(style_name).sub(%r{^/},'')] = file.read
32
+ end
33
+
34
+ after_flush_writes # allows attachment to clean up temp files
35
+
36
+ @queued_for_write = {}
37
+ end
38
+
39
+ def flush_deletes #:nodoc:
40
+ @queued_for_delete.each do |path|
41
+ begin
42
+ log("deleting #{path}")
43
+ tt_bucket.delete(path)
44
+ rescue Errno::ENOENT => e
45
+ # ignore file-not-found, let everything else pass
46
+ end
47
+ end
48
+ @queued_for_delete = []
49
+ end
50
+
51
+ def copy_to_local_file(style, local_dest_path)
52
+ log("copying #{path(style)} to local file #{local_dest_path}")
53
+ local_file = ::File.open(local_dest_path, 'wb')
54
+ tt_bucket[path(style).sub(%r{^/},'')] = local_file.read
55
+ rescue
56
+ warn("cannot copy #{path(style)} to local file #{local_dest_path}")
57
+ false
58
+ end
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "paperclip-tt"
5
+ gem.version = "0.0.1"
6
+ gem.platform = Gem::Platform::RUBY
7
+
8
+ gem.homepage = "https://github.com/totothink/paperclip-tt"
9
+ gem.description = %q{Extends Paperclip with TokyoTyrant storage.}
10
+ gem.summary = gem.description
11
+ gem.authors = ["Aaron"]
12
+ gem.email = ["yalong1976@gmail.com"]
13
+
14
+ gem.files = Dir["lib/**/*"] + ["README.md", "LICENSE", "paperclip-tt.gemspec","CHANGELOG"]
15
+ gem.require_path = "lib"
16
+
17
+ gem.required_ruby_version = ">= 1.9.2"
18
+
19
+ gem.license = "MIT"
20
+
21
+ gem.add_dependency "paperclip", "~> 3.1"
22
+ gem.add_dependency "rufus-tokyo"
23
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paperclip-tt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aaron
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: paperclip
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
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: '3.1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rufus-tokyo
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
+ description: Extends Paperclip with TokyoTyrant storage.
47
+ email:
48
+ - yalong1976@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/paperclip-tt.rb
54
+ - lib/paperclip/storage/tokyo_tyrant.rb
55
+ - lib/paperclip/tokyo_tyrant.rb
56
+ - lib/tokyo_tyrant.rb
57
+ - README.md
58
+ - LICENSE
59
+ - paperclip-tt.gemspec
60
+ - CHANGELOG
61
+ homepage: https://github.com/totothink/paperclip-tt
62
+ licenses:
63
+ - MIT
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: 1.9.2
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.24
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Extends Paperclip with TokyoTyrant storage.
86
+ test_files: []