paperclip-ipfs-storage 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1dbe356be64a25e89e0886b2f94337928f51875b
4
+ data.tar.gz: 99e779dcac60b7204bfed934f2ea8ff3b4a51564
5
+ SHA512:
6
+ metadata.gz: 7a1c2a0d3e41ac544bc5a62a4f8e94d01426f0779f98e8913e425ab9328332cd56676a389c9f8e01cc66cb8aaa7b594d833bba21073cabd7684bb530ca41c166
7
+ data.tar.gz: 1e955ac0e7699c1ca33abc4cb8e8ce4a1b395cdd49d83749ff15f1025a9cabd05bb00b2cbc2d9cc09173777c99930559e76d7d2d7167a0dab91b0d20698349d8
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "https://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem 'ipfs-api', '~> 0.3.0'
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+
11
+ group :development do
12
+ gem 'shoulda', '>= 0'
13
+ gem 'rdoc', '~> 3.12'
14
+ gem 'bundler', '~> 1.0'
15
+ gem 'jeweler', '~> 2.3.5'
16
+ gem 'simplecov', '>= 0'
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,91 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (5.1.0)
5
+ concurrent-ruby (~> 1.0, >= 1.0.2)
6
+ i18n (~> 0.7)
7
+ minitest (~> 5.1)
8
+ tzinfo (~> 1.1)
9
+ addressable (2.5.1)
10
+ public_suffix (~> 2.0, >= 2.0.2)
11
+ builder (3.2.3)
12
+ concurrent-ruby (1.0.5)
13
+ descendants_tracker (0.0.4)
14
+ thread_safe (~> 0.3, >= 0.3.1)
15
+ docile (1.1.5)
16
+ faraday (0.9.2)
17
+ multipart-post (>= 1.2, < 3)
18
+ git (1.3.0)
19
+ github_api (0.11.3)
20
+ addressable (~> 2.3)
21
+ descendants_tracker (~> 0.0.1)
22
+ faraday (~> 0.8, < 0.10)
23
+ hashie (>= 1.2)
24
+ multi_json (>= 1.7.5, < 2.0)
25
+ nokogiri (~> 1.6.0)
26
+ oauth2
27
+ hashie (3.5.5)
28
+ highline (1.7.8)
29
+ i18n (0.8.1)
30
+ ipfs-api (0.3.0)
31
+ jeweler (2.3.5)
32
+ builder
33
+ bundler (>= 1.0)
34
+ git (>= 1.2.5)
35
+ github_api (~> 0.11.0)
36
+ highline (>= 1.6.15)
37
+ nokogiri (>= 1.5.10)
38
+ psych (~> 2.2)
39
+ rake
40
+ rdoc
41
+ semver2
42
+ json (1.8.6)
43
+ jwt (1.5.6)
44
+ mini_portile2 (2.1.0)
45
+ minitest (5.10.1)
46
+ multi_json (1.12.1)
47
+ multi_xml (0.6.0)
48
+ multipart-post (2.0.0)
49
+ nokogiri (1.6.8.1)
50
+ mini_portile2 (~> 2.1.0)
51
+ oauth2 (1.3.1)
52
+ faraday (>= 0.8, < 0.12)
53
+ jwt (~> 1.0)
54
+ multi_json (~> 1.3)
55
+ multi_xml (~> 0.5)
56
+ rack (>= 1.2, < 3)
57
+ psych (2.2.2)
58
+ public_suffix (2.0.5)
59
+ rack (2.0.1)
60
+ rake (12.0.0)
61
+ rdoc (3.12.2)
62
+ json (~> 1.4)
63
+ semver2 (3.4.2)
64
+ shoulda (3.5.0)
65
+ shoulda-context (~> 1.0, >= 1.0.1)
66
+ shoulda-matchers (>= 1.4.1, < 3.0)
67
+ shoulda-context (1.2.2)
68
+ shoulda-matchers (2.8.0)
69
+ activesupport (>= 3.0.0)
70
+ simplecov (0.14.1)
71
+ docile (~> 1.1.0)
72
+ json (>= 1.8, < 3)
73
+ simplecov-html (~> 0.10.0)
74
+ simplecov-html (0.10.0)
75
+ thread_safe (0.3.6)
76
+ tzinfo (1.2.3)
77
+ thread_safe (~> 0.1)
78
+
79
+ PLATFORMS
80
+ ruby
81
+
82
+ DEPENDENCIES
83
+ bundler (~> 1.0)
84
+ ipfs-api (~> 0.3.0)
85
+ jeweler (~> 2.3.5)
86
+ rdoc (~> 3.12)
87
+ shoulda
88
+ simplecov
89
+
90
+ BUNDLED WITH
91
+ 1.14.6
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 mecab <mecab@misosi.ru>
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,46 @@
1
+ Paperclip IPFS Storage
2
+ ======================
3
+
4
+ This gem extends the [Paperclip](https://github.com/thoughtbot/paperclip) so that you can save file on [IPFS](https://ipfs.io/) network.
5
+
6
+ Installation
7
+ ============
8
+
9
+ ```bash
10
+ gem "paperclip-ipfs-storage"
11
+ ```
12
+
13
+ or put it on the Gemfile.
14
+
15
+ Usage
16
+ =====
17
+
18
+ Add `attachment` type field into the schema as usual, then add `string` type field as `[field_name]_ipfs_hash`. For example:
19
+
20
+ ```ruby
21
+ class CreateMediaAttachments < ActiveRecord::Migration[5.0]
22
+ def change
23
+ create_table :media_attachments do |t|
24
+ t.attachment :file
25
+ t.string :file_ipfs_hash, :file_ipfs_hash, null: true, default: nil
26
+ end
27
+ end
28
+ end
29
+ ```
30
+
31
+ Then specify `:ipfs` for the `:storage` option and `':gateway_url'` for the `:url` in the model. For example:
32
+
33
+ ```ruby
34
+ class MediaAttachment < ActiveRecord::Base
35
+ has_attached_file :file,
36
+ :storage => :ipfs,
37
+ :url => ':gateway_url'
38
+ end
39
+ ```
40
+
41
+ Limitation
42
+ ==========
43
+
44
+ You cannot remove the file uploaded. This is due to the design of IPFS [^1].
45
+
46
+ [^1]: https://github.com/ipfs/faq/issues/9
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "paperclip-ipfs-storage"
18
+ gem.homepage = "http://github.com/mecab/paperclip-ipfs-storage"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{The paperclip storage library to save files on IPFS network.}
21
+ gem.description = %Q{The paperclip storage library to save files on IPFS network.}
22
+ gem.email = "mecab@misosi.ru"
23
+ gem.authors = ["mecab"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['test'].execute
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "paperclip-ipfs-storage #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.9.0
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'paperclip', 'storage', 'ipfs')
@@ -0,0 +1,92 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'tempfile'
5
+
6
+ module Paperclip
7
+ module Storage
8
+ module Ipfs
9
+ def self.extended(base)
10
+ begin
11
+ require 'ipfs-api'
12
+ rescue LoadError => e
13
+ e.message << '(You may need to install the ipfs-api gem)'
14
+ raise e
15
+ end
16
+
17
+ base.instance_eval do
18
+ @api_url = @options[:ipfs_api_url] || 'http://127.0.0.1:5001'
19
+ @ipfs = IPFS::Connection.new(@api_url)
20
+ end
21
+
22
+ Paperclip.interpolates(:item_hash) do |attachment, _|
23
+ attachment.hash
24
+ end
25
+ Paperclip.interpolates(:directory) do |attachment, style_name|
26
+ attachment.directory style_name
27
+ end
28
+ Paperclip.interpolates(:gateway_url) do |attachment, style_name|
29
+ attachment.gateway_url style_name
30
+ end
31
+ end
32
+
33
+ def hash
34
+ instance_read('ipfs_hash'.to_sym)
35
+ end
36
+
37
+ def directory(style_name = default_style)
38
+ "#{hash}/#{style_name}"
39
+ end
40
+
41
+ def gateway_url(style_name = default_style)
42
+ filename = Paperclip::Interpolations.filename(self, style_name.to_sym)
43
+ "https://gateway.ipfs.io/ipfs/#{directory style_name}/#{filename}"
44
+ end
45
+
46
+ def exists?(style_name = default_style)
47
+ hash(style_name).present?
48
+ end
49
+
50
+ def copy_to_local_file(style_name = default_style, destination_path)
51
+ File.open(destination_path, 'wb') do |fd|
52
+ if @queued_for_write[style_name]
53
+ IO.copy_stream(@queued_for_write[style_name], fd)
54
+ else
55
+ directory = directory(style_name)
56
+ filename = Paperclip::Interpolations.filename(self, style_name.to_sym)
57
+ fd.write(@ipfs.cat("#{directory}/#{filename}"))
58
+ end
59
+ end
60
+ end
61
+
62
+ def flush_writes #:nodoc:
63
+ return if @queued_for_write.empty?
64
+
65
+ Dir.mktmpdir do |tempdir|
66
+ Dir.chdir(tempdir) do
67
+ @attr = queued_for_write.each do |style_name, file|
68
+ Dir.mkdir(style_name.to_s)
69
+ File.open(Pathname.new(style_name.to_s).join(original_filename), 'wb') do |fd|
70
+ IO.copy_stream(file, fd)
71
+ end
72
+ end
73
+ end
74
+ @ipfs.add Dir.new(tempdir) do |node|
75
+ if node.name == File.basename(tempdir)
76
+ instance_write('ipfs_hash'.to_sym, node.hash)
77
+ end
78
+ end
79
+ end
80
+
81
+ after_flush_writes
82
+ @queued_for_write.clear
83
+ instance.save
84
+ end
85
+
86
+ def flush_deletes #:nodoc:
87
+ log('deleting is not supported on IPFS')
88
+ @queued_for_delete.clear
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: paperclip-ipfs-storage 0.9.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "paperclip-ipfs-storage".freeze
9
+ s.version = "0.9.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["mecab".freeze]
14
+ s.date = "2017-05-07"
15
+ s.description = "The paperclip storage library to save files on IPFS network.".freeze
16
+ s.email = "mecab@misosi.ru".freeze
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/paperclip-ipfs-storage.rb",
30
+ "lib/paperclip/storage/ipfs.rb",
31
+ "paperclip-ipfs-storage.gemspec",
32
+ "test/helper.rb",
33
+ "test/test_paperclip-ipfs-storage.rb"
34
+ ]
35
+ s.homepage = "http://github.com/mecab/paperclip-ipfs-storage".freeze
36
+ s.licenses = ["MIT".freeze]
37
+ s.rubygems_version = "2.6.11".freeze
38
+ s.summary = "The paperclip storage library to save files on IPFS network.".freeze
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 4
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<ipfs-api>.freeze, ["~> 0.3.0"])
45
+ s.add_development_dependency(%q<shoulda>.freeze, [">= 0"])
46
+ s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
47
+ s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
48
+ s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.3.5"])
49
+ s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<ipfs-api>.freeze, ["~> 0.3.0"])
52
+ s.add_dependency(%q<shoulda>.freeze, [">= 0"])
53
+ s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
54
+ s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
55
+ s.add_dependency(%q<jeweler>.freeze, ["~> 2.3.5"])
56
+ s.add_dependency(%q<simplecov>.freeze, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<ipfs-api>.freeze, ["~> 0.3.0"])
60
+ s.add_dependency(%q<shoulda>.freeze, [">= 0"])
61
+ s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
62
+ s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
63
+ s.add_dependency(%q<jeweler>.freeze, ["~> 2.3.5"])
64
+ s.add_dependency(%q<simplecov>.freeze, [">= 0"])
65
+ end
66
+ end
67
+
data/test/helper.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_adapter 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ require 'rubygems'
18
+ require 'bundler'
19
+ begin
20
+ Bundler.setup(:default, :development)
21
+ rescue Bundler::BundlerError => e
22
+ $stderr.puts e.message
23
+ $stderr.puts "Run `bundle install` to install missing gems"
24
+ exit e.status_code
25
+ end
26
+ require 'test/unit'
27
+ require 'shoulda'
28
+
29
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
30
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
31
+ require 'paperclip-ipfs-storage'
32
+
33
+ class Test::Unit::TestCase
34
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestPaperclipIpfsStorage < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paperclip-ipfs-storage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - mecab
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ipfs-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.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.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: shoulda
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rdoc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.3.5
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.3.5
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: The paperclip storage library to save files on IPFS network.
98
+ email: mecab@misosi.ru
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files:
102
+ - LICENSE
103
+ - README.md
104
+ files:
105
+ - ".document"
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE
109
+ - README.md
110
+ - Rakefile
111
+ - VERSION
112
+ - lib/paperclip-ipfs-storage.rb
113
+ - lib/paperclip/storage/ipfs.rb
114
+ - paperclip-ipfs-storage.gemspec
115
+ - test/helper.rb
116
+ - test/test_paperclip-ipfs-storage.rb
117
+ homepage: http://github.com/mecab/paperclip-ipfs-storage
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.6.11
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: The paperclip storage library to save files on IPFS network.
141
+ test_files: []