paperclip-riak 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ *.swp
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.3-p0@paperclip-riak --create
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in paperclip-riak.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/Readme.md ADDED
@@ -0,0 +1,36 @@
1
+ # Paperclip-Riak
2
+
3
+ paperclip-riak is a paperclip storage module that allow us to store uploaded files to [Riak](http://basho.com/products/riak-overview).
4
+ There are many use cases where storing file in riak is acceptable, especially when we only need to store small files (e.g image thumbnails).
5
+
6
+ ## Usage
7
+
8
+ ```rb
9
+ # Gemfile
10
+ gem papeclip-riak
11
+ ```
12
+
13
+ ```rb
14
+ class Image < ActiveRecord::Base
15
+ has_attached_file :data,
16
+ :storage => :riak,
17
+ :riak_hosts => [
18
+ {:host => '127.0.0.1:8098'}
19
+ ],
20
+ :riak_bucket => 'images',
21
+ :riak_endpoint => 'http://127.0.0.1:8098/riak',
22
+ :path => ":id_:style_:filename"
23
+ end
24
+ ```
25
+
26
+ ## License
27
+
28
+ The MIT License (MIT)
29
+
30
+ Copyright © 2012 Nugroho Herucahyono
31
+
32
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
33
+
34
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
35
+
36
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,70 @@
1
+ require 'paperclip'
2
+ require 'riak'
3
+
4
+ module Paperclip
5
+ module Storage
6
+ module Riak
7
+
8
+ def self.extended(base)
9
+ attr_accessor :riak_hosts, :riak_bucket, :riak_endpoint
10
+
11
+ base.instance_eval do
12
+ self.setup_options
13
+ end
14
+ end
15
+
16
+ def url(style=default_style, options={})
17
+ "#{@riak_endpoint}/#{@riak_bucket}/#{path(style)}"
18
+ end
19
+
20
+ def riak
21
+ @riak ||= ::Riak::Client.new(@client_options)
22
+ end
23
+
24
+ def bucket
25
+ @bucket ||= riak.bucket(@riak_bucket)
26
+ end
27
+
28
+ def setup_options
29
+ @client_options = {
30
+ :nodes => @options[:riak_hosts]
31
+ }
32
+ @riak_bucket = @options[:riak_bucket]
33
+ @riak_endpoint = @options[:riak_endpoint]
34
+ end
35
+
36
+ def exists?(style = default_style)
37
+ if original_filename
38
+ @bucket.exists?(path(style))
39
+ else
40
+ false
41
+ end
42
+ end
43
+
44
+ def flush_writes
45
+ @queued_for_write.each do |style, file|
46
+ object = ::Riak::RObject.new(bucket, path(style))
47
+ object.raw_data = File.read(file.path)
48
+ object.content_type = file.content_type.to_s.strip
49
+ object.store
50
+ end
51
+ @queued_for_write = {}
52
+ end
53
+
54
+ def flush_deletes
55
+ @queued_for_delete.each do |path|
56
+ bucket.delete path
57
+ end
58
+ @queued_for_delete = []
59
+ end
60
+
61
+ def copy_to_local_file(style, local_dest_path)
62
+ ::File.open(local_dest_path, 'wb') do |local_file|
63
+ file = bucket.get(path(style))
64
+ local_file.write(file.raw_data)
65
+ end
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "paperclip-riak"
6
+ s.version = "0.0.2"
7
+ s.authors = ["Nugroho Herucahyono"]
8
+ s.email = ["xinuc@xinuc.org"]
9
+ s.homepage = "https://github.com/xinuc/paperclip-riak"
10
+ s.summary = %q{Use riak as paperclip file storage}
11
+ s.description = %q{Paperclip storage module that allow us to store uploaded files to Riak}
12
+
13
+ s.license = 'MIT'
14
+
15
+ s.rubyforge_project = "paperclip-riak"
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_runtime_dependency "paperclip"
23
+ s.add_runtime_dependency "riak-client"
24
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paperclip-riak
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nugroho Herucahyono
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: paperclip
16
+ requirement: &5863180 !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: *5863180
25
+ - !ruby/object:Gem::Dependency
26
+ name: riak-client
27
+ requirement: &5862600 !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: *5862600
36
+ description: Paperclip storage module that allow us to store uploaded files to Riak
37
+ email:
38
+ - xinuc@xinuc.org
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - .rvmrc
45
+ - Gemfile
46
+ - Rakefile
47
+ - Readme.md
48
+ - lib/paperclip-riak.rb
49
+ - paperclip-riak.gemspec
50
+ homepage: https://github.com/xinuc/paperclip-riak
51
+ licenses:
52
+ - MIT
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-riak
71
+ rubygems_version: 1.8.10
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Use riak as paperclip file storage
75
+ test_files: []