dragonfly-activerecord 0.0.1

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: 71dee4838386007ab3187a967c5358452dcea848
4
+ data.tar.gz: d754f01bb97796d20bebccec6f29ec38e52ae077
5
+ SHA512:
6
+ metadata.gz: 3160ed764fa8ccd08566c18b762b83a4a6166f54684ca82259ed01324a23f7f82d5566117f21bb03d621a4ea90742e1168f0560256c0bafcdda493e1f4f7545e
7
+ data.tar.gz: bb021fb1742c9270608b91b8b7a178b4bda4df1ced7371a74899db468db033e7c2eb22059512636725b91d446d9999ec46c5c3fef991068ee443dfa55adc42c4
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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p353
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ rvm:
2
+ - "1.9.3"
3
+ - "2.0.0"
4
+ - "2.1.0"
5
+ gemfile:
6
+ - gemfiles/rails32.gemfile
7
+ - gemfiles/rails40_pg.gemfile
8
+ - gemfiles/rails40_mysql.gemfile
9
+ - gemfiles/rails40_sqlite.gemfile
10
+ - gemfiles/rails40.gemfile
11
+ before_install:
12
+ - gem update bundler
13
+ - bundle install
14
+ bundler_args:
15
+ before_script:
16
+ - psql -c 'create database dar_test;' -U postgres
17
+ - mysql -e 'create database dar_test;'
data/Appraisals ADDED
@@ -0,0 +1,19 @@
1
+ appraise "rails32" do
2
+ gem "activerecord", "~> 3.2.6"
3
+ end
4
+
5
+ appraise "rails40-pg" do
6
+ gem "activerecord", "~> 4.0.2"
7
+ end
8
+
9
+ appraise "rails40-mysql" do
10
+ gem "activerecord", "~> 4.0.2"
11
+ end
12
+
13
+ appraise "rails40-sqlite" do
14
+ gem "activerecord", "~> 4.0.2"
15
+ end
16
+
17
+ appraise "rails40" do
18
+ gem "activerecord", "~> 4.0.2"
19
+ end
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source ENV.fetch('GEM_SOURCE', 'https://rubygems.org')
2
+
3
+ # Specify your gem's dependencies in dragonfly-ar-store.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 HouseTrip Ltd.
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,68 @@
1
+ # dragonfly-activerecord
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/dragonfly-activerecord.png)](http://badge.fury.io/rb/dragonfly-activerecord)
4
+ [![Build Status](https://travis-ci.org/mezis/dragonfly-activerecord.png?branch=master)](https://travis-ci.org/mezis/dragonfly-activerecord)
5
+ [![Dependency Status](https://gemnasium.com/mezis/dragonfly-activerecord.png)](https://gemnasium.com/mezis/dragonfly-activerecord)
6
+ [![Code Climate](https://codeclimate.com/github/mezis/dragonfly-activerecord.png)](https://codeclimate.com/github/mezis/dragonfly-activerecord)
7
+
8
+ Provides a data store for [Dragonfly](https://github.com/markevans/dragonfly),
9
+ backed by ActiveRecord.
10
+
11
+ Requires a Rails application using Dragonfly 1.0+.
12
+
13
+
14
+ ## Why?
15
+
16
+ Because there's a fat chance our app already has a database. Why bother with S3
17
+ when your DB can do the job just fine?
18
+
19
+ Yes, storing files in a relational database may be a bad idea at scale, but for
20
+ many use cases (up to a few gigabytes of storage) it really eases the
21
+ maintenance burden.
22
+
23
+
24
+ ## Installation
25
+
26
+ Add this line to your application's Gemfile:
27
+
28
+ gem 'dragonfly-activerecord'
29
+
30
+ Create a migration:
31
+
32
+ $ rails generate migration add_dragonfly_storage
33
+
34
+ Edit the migration file:
35
+
36
+ ```ruby
37
+ require 'dragonfly-activerecord/migration'
38
+
39
+ class AddDragonflyStorage < ActiveRecord::Migration
40
+ include Dragonfly::ActiveRecord::Migration
41
+ end
42
+ ```
43
+
44
+ Run the migration:
45
+
46
+ $ rake db:migrate
47
+
48
+ Configure Dragonfly itself (in `config/initializers/dragonfly.rb`, typically):
49
+
50
+ ```ruby
51
+ require 'dragonfly-activerecord/store'
52
+
53
+ Dragonfly.app.configure do
54
+ # ... your existing configuration here
55
+ datastore Storage::DataStore.new
56
+ end
57
+ ```
58
+
59
+ ... and you're good to go!
60
+
61
+
62
+ ## Contributing
63
+
64
+ 1. Fork it
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ require 'appraisal'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dragonfly-activerecord/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'dragonfly-activerecord'
8
+ spec.version = Dragonfly::ActiveRecord::VERSION
9
+ spec.authors = ['Julien Letessier']
10
+ spec.email = ['julien.letessier@gmail.com']
11
+ spec.summary = %q{ActiveRecord-backed data store for Dragonfly}
12
+ spec.description = spec.summary
13
+ spec.homepage = 'https://github.com/mezis/dragonfly-activerecord'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'appraisal'
25
+ spec.add_development_dependency 'sqlite3'
26
+ spec.add_development_dependency 'pg'
27
+ spec.add_development_dependency 'mysql2'
28
+ spec.add_development_dependency 'guard'
29
+ spec.add_development_dependency 'guard-rspec'
30
+
31
+ spec.add_dependency 'activerecord', '>= 3.2.6'
32
+ end
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 3.2.6"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,87 @@
1
+ PATH
2
+ remote: /Users/mezis/Dropbox/Development/dragonfly-activerecord
3
+ specs:
4
+ dragonfly-activerecord (0.0.1)
5
+ activerecord (>= 3.2.6)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (3.2.15)
11
+ activesupport (= 3.2.15)
12
+ builder (~> 3.0.0)
13
+ activerecord (3.2.15)
14
+ activemodel (= 3.2.15)
15
+ activesupport (= 3.2.15)
16
+ arel (~> 3.0.2)
17
+ tzinfo (~> 0.3.29)
18
+ activesupport (3.2.15)
19
+ i18n (~> 0.6, >= 0.6.4)
20
+ multi_json (~> 1.0)
21
+ appraisal (0.5.2)
22
+ bundler
23
+ rake
24
+ arel (3.0.3)
25
+ builder (3.0.4)
26
+ celluloid (0.15.2)
27
+ timers (~> 1.1.0)
28
+ coderay (1.1.0)
29
+ diff-lcs (1.2.5)
30
+ ffi (1.9.3)
31
+ formatador (0.2.4)
32
+ guard (2.2.4)
33
+ formatador (>= 0.2.4)
34
+ listen (~> 2.1)
35
+ lumberjack (~> 1.0)
36
+ pry (>= 0.9.12)
37
+ thor (>= 0.18.1)
38
+ guard-rspec (4.2.0)
39
+ guard (>= 2.1.1)
40
+ rspec (>= 2.14, < 4.0)
41
+ i18n (0.6.9)
42
+ listen (2.4.0)
43
+ celluloid (>= 0.15.2)
44
+ rb-fsevent (>= 0.9.3)
45
+ rb-inotify (>= 0.9)
46
+ lumberjack (1.0.4)
47
+ method_source (0.8.2)
48
+ multi_json (1.8.2)
49
+ mysql2 (0.3.14)
50
+ pg (0.17.1)
51
+ pry (0.9.12.4)
52
+ coderay (~> 1.0)
53
+ method_source (~> 0.8)
54
+ slop (~> 3.4)
55
+ rake (10.1.1)
56
+ rb-fsevent (0.9.3)
57
+ rb-inotify (0.9.2)
58
+ ffi (>= 0.5.0)
59
+ rspec (2.14.1)
60
+ rspec-core (~> 2.14.0)
61
+ rspec-expectations (~> 2.14.0)
62
+ rspec-mocks (~> 2.14.0)
63
+ rspec-core (2.14.7)
64
+ rspec-expectations (2.14.4)
65
+ diff-lcs (>= 1.1.3, < 2.0)
66
+ rspec-mocks (2.14.4)
67
+ slop (3.4.7)
68
+ sqlite3 (1.3.8)
69
+ thor (0.18.1)
70
+ timers (1.1.0)
71
+ tzinfo (0.3.38)
72
+
73
+ PLATFORMS
74
+ ruby
75
+
76
+ DEPENDENCIES
77
+ activerecord (~> 3.2.6)
78
+ appraisal
79
+ bundler (~> 1.3)
80
+ dragonfly-activerecord!
81
+ guard
82
+ guard-rspec
83
+ mysql2
84
+ pg
85
+ rake
86
+ rspec
87
+ sqlite3
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.0.2"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,95 @@
1
+ PATH
2
+ remote: /Users/mezis/Dropbox/Development/dragonfly-activerecord
3
+ specs:
4
+ dragonfly-activerecord (0.0.1)
5
+ activerecord (>= 3.2.6)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (4.0.2)
11
+ activesupport (= 4.0.2)
12
+ builder (~> 3.1.0)
13
+ activerecord (4.0.2)
14
+ activemodel (= 4.0.2)
15
+ activerecord-deprecated_finders (~> 1.0.2)
16
+ activesupport (= 4.0.2)
17
+ arel (~> 4.0.0)
18
+ activerecord-deprecated_finders (1.0.3)
19
+ activesupport (4.0.2)
20
+ i18n (~> 0.6, >= 0.6.4)
21
+ minitest (~> 4.2)
22
+ multi_json (~> 1.3)
23
+ thread_safe (~> 0.1)
24
+ tzinfo (~> 0.3.37)
25
+ appraisal (0.5.2)
26
+ bundler
27
+ rake
28
+ arel (4.0.1)
29
+ atomic (1.1.14)
30
+ builder (3.1.4)
31
+ celluloid (0.15.2)
32
+ timers (~> 1.1.0)
33
+ coderay (1.1.0)
34
+ diff-lcs (1.2.5)
35
+ ffi (1.9.3)
36
+ formatador (0.2.4)
37
+ guard (2.2.4)
38
+ formatador (>= 0.2.4)
39
+ listen (~> 2.1)
40
+ lumberjack (~> 1.0)
41
+ pry (>= 0.9.12)
42
+ thor (>= 0.18.1)
43
+ guard-rspec (4.2.0)
44
+ guard (>= 2.1.1)
45
+ rspec (>= 2.14, < 4.0)
46
+ i18n (0.6.9)
47
+ listen (2.4.0)
48
+ celluloid (>= 0.15.2)
49
+ rb-fsevent (>= 0.9.3)
50
+ rb-inotify (>= 0.9)
51
+ lumberjack (1.0.4)
52
+ method_source (0.8.2)
53
+ minitest (4.7.5)
54
+ multi_json (1.8.2)
55
+ mysql2 (0.3.14)
56
+ pg (0.17.1)
57
+ pry (0.9.12.4)
58
+ coderay (~> 1.0)
59
+ method_source (~> 0.8)
60
+ slop (~> 3.4)
61
+ rake (10.1.1)
62
+ rb-fsevent (0.9.3)
63
+ rb-inotify (0.9.2)
64
+ ffi (>= 0.5.0)
65
+ rspec (2.14.1)
66
+ rspec-core (~> 2.14.0)
67
+ rspec-expectations (~> 2.14.0)
68
+ rspec-mocks (~> 2.14.0)
69
+ rspec-core (2.14.7)
70
+ rspec-expectations (2.14.4)
71
+ diff-lcs (>= 1.1.3, < 2.0)
72
+ rspec-mocks (2.14.4)
73
+ slop (3.4.7)
74
+ sqlite3 (1.3.8)
75
+ thor (0.18.1)
76
+ thread_safe (0.1.3)
77
+ atomic
78
+ timers (1.1.0)
79
+ tzinfo (0.3.38)
80
+
81
+ PLATFORMS
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ activerecord (~> 4.0.2)
86
+ appraisal
87
+ bundler (~> 1.3)
88
+ dragonfly-activerecord!
89
+ guard
90
+ guard-rspec
91
+ mysql2
92
+ pg
93
+ rake
94
+ rspec
95
+ sqlite3
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.0.2"
6
+ ENV['DAR_ADAPTER'] = 'mysql'
7
+
8
+ gemspec :path=>"../"
@@ -0,0 +1,95 @@
1
+ PATH
2
+ remote: /Users/mezis/Dropbox/Development/dragonfly-activerecord
3
+ specs:
4
+ dragonfly-activerecord (0.0.1)
5
+ activerecord (>= 3.2.6)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (4.0.2)
11
+ activesupport (= 4.0.2)
12
+ builder (~> 3.1.0)
13
+ activerecord (4.0.2)
14
+ activemodel (= 4.0.2)
15
+ activerecord-deprecated_finders (~> 1.0.2)
16
+ activesupport (= 4.0.2)
17
+ arel (~> 4.0.0)
18
+ activerecord-deprecated_finders (1.0.3)
19
+ activesupport (4.0.2)
20
+ i18n (~> 0.6, >= 0.6.4)
21
+ minitest (~> 4.2)
22
+ multi_json (~> 1.3)
23
+ thread_safe (~> 0.1)
24
+ tzinfo (~> 0.3.37)
25
+ appraisal (0.5.2)
26
+ bundler
27
+ rake
28
+ arel (4.0.1)
29
+ atomic (1.1.14)
30
+ builder (3.1.4)
31
+ celluloid (0.15.2)
32
+ timers (~> 1.1.0)
33
+ coderay (1.1.0)
34
+ diff-lcs (1.2.5)
35
+ ffi (1.9.3)
36
+ formatador (0.2.4)
37
+ guard (2.2.4)
38
+ formatador (>= 0.2.4)
39
+ listen (~> 2.1)
40
+ lumberjack (~> 1.0)
41
+ pry (>= 0.9.12)
42
+ thor (>= 0.18.1)
43
+ guard-rspec (4.2.0)
44
+ guard (>= 2.1.1)
45
+ rspec (>= 2.14, < 4.0)
46
+ i18n (0.6.9)
47
+ listen (2.4.0)
48
+ celluloid (>= 0.15.2)
49
+ rb-fsevent (>= 0.9.3)
50
+ rb-inotify (>= 0.9)
51
+ lumberjack (1.0.4)
52
+ method_source (0.8.2)
53
+ minitest (4.7.5)
54
+ multi_json (1.8.2)
55
+ mysql2 (0.3.14)
56
+ pg (0.17.1)
57
+ pry (0.9.12.4)
58
+ coderay (~> 1.0)
59
+ method_source (~> 0.8)
60
+ slop (~> 3.4)
61
+ rake (10.1.1)
62
+ rb-fsevent (0.9.3)
63
+ rb-inotify (0.9.2)
64
+ ffi (>= 0.5.0)
65
+ rspec (2.14.1)
66
+ rspec-core (~> 2.14.0)
67
+ rspec-expectations (~> 2.14.0)
68
+ rspec-mocks (~> 2.14.0)
69
+ rspec-core (2.14.7)
70
+ rspec-expectations (2.14.4)
71
+ diff-lcs (>= 1.1.3, < 2.0)
72
+ rspec-mocks (2.14.4)
73
+ slop (3.4.7)
74
+ sqlite3 (1.3.8)
75
+ thor (0.18.1)
76
+ thread_safe (0.1.3)
77
+ atomic
78
+ timers (1.1.0)
79
+ tzinfo (0.3.38)
80
+
81
+ PLATFORMS
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ activerecord (~> 4.0.2)
86
+ appraisal
87
+ bundler (~> 1.3)
88
+ dragonfly-activerecord!
89
+ guard
90
+ guard-rspec
91
+ mysql2
92
+ pg
93
+ rake
94
+ rspec
95
+ sqlite3
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.0.2"
6
+ ENV['DAR_ADAPTER'] = 'postgresql'
7
+
8
+ gemspec :path=>"../"
@@ -0,0 +1,95 @@
1
+ PATH
2
+ remote: /Users/mezis/Dropbox/Development/dragonfly-activerecord
3
+ specs:
4
+ dragonfly-activerecord (0.0.1)
5
+ activerecord (>= 3.2.6)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (4.0.2)
11
+ activesupport (= 4.0.2)
12
+ builder (~> 3.1.0)
13
+ activerecord (4.0.2)
14
+ activemodel (= 4.0.2)
15
+ activerecord-deprecated_finders (~> 1.0.2)
16
+ activesupport (= 4.0.2)
17
+ arel (~> 4.0.0)
18
+ activerecord-deprecated_finders (1.0.3)
19
+ activesupport (4.0.2)
20
+ i18n (~> 0.6, >= 0.6.4)
21
+ minitest (~> 4.2)
22
+ multi_json (~> 1.3)
23
+ thread_safe (~> 0.1)
24
+ tzinfo (~> 0.3.37)
25
+ appraisal (0.5.2)
26
+ bundler
27
+ rake
28
+ arel (4.0.1)
29
+ atomic (1.1.14)
30
+ builder (3.1.4)
31
+ celluloid (0.15.2)
32
+ timers (~> 1.1.0)
33
+ coderay (1.1.0)
34
+ diff-lcs (1.2.5)
35
+ ffi (1.9.3)
36
+ formatador (0.2.4)
37
+ guard (2.2.4)
38
+ formatador (>= 0.2.4)
39
+ listen (~> 2.1)
40
+ lumberjack (~> 1.0)
41
+ pry (>= 0.9.12)
42
+ thor (>= 0.18.1)
43
+ guard-rspec (4.2.0)
44
+ guard (>= 2.1.1)
45
+ rspec (>= 2.14, < 4.0)
46
+ i18n (0.6.9)
47
+ listen (2.4.0)
48
+ celluloid (>= 0.15.2)
49
+ rb-fsevent (>= 0.9.3)
50
+ rb-inotify (>= 0.9)
51
+ lumberjack (1.0.4)
52
+ method_source (0.8.2)
53
+ minitest (4.7.5)
54
+ multi_json (1.8.2)
55
+ mysql2 (0.3.14)
56
+ pg (0.17.1)
57
+ pry (0.9.12.4)
58
+ coderay (~> 1.0)
59
+ method_source (~> 0.8)
60
+ slop (~> 3.4)
61
+ rake (10.1.1)
62
+ rb-fsevent (0.9.3)
63
+ rb-inotify (0.9.2)
64
+ ffi (>= 0.5.0)
65
+ rspec (2.14.1)
66
+ rspec-core (~> 2.14.0)
67
+ rspec-expectations (~> 2.14.0)
68
+ rspec-mocks (~> 2.14.0)
69
+ rspec-core (2.14.7)
70
+ rspec-expectations (2.14.4)
71
+ diff-lcs (>= 1.1.3, < 2.0)
72
+ rspec-mocks (2.14.4)
73
+ slop (3.4.7)
74
+ sqlite3 (1.3.8)
75
+ thor (0.18.1)
76
+ thread_safe (0.1.3)
77
+ atomic
78
+ timers (1.1.0)
79
+ tzinfo (0.3.38)
80
+
81
+ PLATFORMS
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ activerecord (~> 4.0.2)
86
+ appraisal
87
+ bundler (~> 1.3)
88
+ dragonfly-activerecord!
89
+ guard
90
+ guard-rspec
91
+ mysql2
92
+ pg
93
+ rake
94
+ rspec
95
+ sqlite3
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.0.2"
6
+ ENV['DAR_ADAPTER'] = 'sqlite3'
7
+
8
+ gemspec :path=>"../"
@@ -0,0 +1,95 @@
1
+ PATH
2
+ remote: /Users/mezis/Dropbox/Development/dragonfly-activerecord
3
+ specs:
4
+ dragonfly-activerecord (0.0.1)
5
+ activerecord (>= 3.2.6)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (4.0.2)
11
+ activesupport (= 4.0.2)
12
+ builder (~> 3.1.0)
13
+ activerecord (4.0.2)
14
+ activemodel (= 4.0.2)
15
+ activerecord-deprecated_finders (~> 1.0.2)
16
+ activesupport (= 4.0.2)
17
+ arel (~> 4.0.0)
18
+ activerecord-deprecated_finders (1.0.3)
19
+ activesupport (4.0.2)
20
+ i18n (~> 0.6, >= 0.6.4)
21
+ minitest (~> 4.2)
22
+ multi_json (~> 1.3)
23
+ thread_safe (~> 0.1)
24
+ tzinfo (~> 0.3.37)
25
+ appraisal (0.5.2)
26
+ bundler
27
+ rake
28
+ arel (4.0.1)
29
+ atomic (1.1.14)
30
+ builder (3.1.4)
31
+ celluloid (0.15.2)
32
+ timers (~> 1.1.0)
33
+ coderay (1.1.0)
34
+ diff-lcs (1.2.5)
35
+ ffi (1.9.3)
36
+ formatador (0.2.4)
37
+ guard (2.2.4)
38
+ formatador (>= 0.2.4)
39
+ listen (~> 2.1)
40
+ lumberjack (~> 1.0)
41
+ pry (>= 0.9.12)
42
+ thor (>= 0.18.1)
43
+ guard-rspec (4.2.0)
44
+ guard (>= 2.1.1)
45
+ rspec (>= 2.14, < 4.0)
46
+ i18n (0.6.9)
47
+ listen (2.4.0)
48
+ celluloid (>= 0.15.2)
49
+ rb-fsevent (>= 0.9.3)
50
+ rb-inotify (>= 0.9)
51
+ lumberjack (1.0.4)
52
+ method_source (0.8.2)
53
+ minitest (4.7.5)
54
+ multi_json (1.8.2)
55
+ mysql2 (0.3.14)
56
+ pg (0.17.1)
57
+ pry (0.9.12.4)
58
+ coderay (~> 1.0)
59
+ method_source (~> 0.8)
60
+ slop (~> 3.4)
61
+ rake (10.1.1)
62
+ rb-fsevent (0.9.3)
63
+ rb-inotify (0.9.2)
64
+ ffi (>= 0.5.0)
65
+ rspec (2.14.1)
66
+ rspec-core (~> 2.14.0)
67
+ rspec-expectations (~> 2.14.0)
68
+ rspec-mocks (~> 2.14.0)
69
+ rspec-core (2.14.7)
70
+ rspec-expectations (2.14.4)
71
+ diff-lcs (>= 1.1.3, < 2.0)
72
+ rspec-mocks (2.14.4)
73
+ slop (3.4.7)
74
+ sqlite3 (1.3.8)
75
+ thor (0.18.1)
76
+ thread_safe (0.1.3)
77
+ atomic
78
+ timers (1.1.0)
79
+ tzinfo (0.3.38)
80
+
81
+ PLATFORMS
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ activerecord (~> 4.0.2)
86
+ appraisal
87
+ bundler (~> 1.3)
88
+ dragonfly-activerecord!
89
+ guard
90
+ guard-rspec
91
+ mysql2
92
+ pg
93
+ rake
94
+ rspec
95
+ sqlite3
@@ -0,0 +1,24 @@
1
+ require 'dragonfly-activerecord'
2
+ require 'active_record'
3
+ require 'zlib'
4
+ require 'base64'
5
+
6
+ module Dragonfly::ActiveRecord
7
+ class Chunk < ActiveRecord::Base
8
+ self.table_name = 'storage_chunks'
9
+
10
+ belongs_to :file, class_name: 'Dragonfly::ActiveRecord::File', inverse_of: :chunks
11
+
12
+ validates_presence_of :file
13
+ validates_presence_of :encoded_data
14
+
15
+ def data=(raw_data)
16
+ compressed_data = Zlib::Deflate.deflate(raw_data)
17
+ self.encoded_data = Base64.encode64(compressed_data)
18
+ end
19
+
20
+ def data
21
+ Zlib::Inflate.inflate Base64.decode64(self.encoded_data)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,44 @@
1
+ require 'dragonfly-activerecord'
2
+ require 'dragonfly-activerecord/chunk'
3
+ require 'active_record'
4
+
5
+ module Dragonfly::ActiveRecord
6
+ class File < ActiveRecord::Base
7
+ self.table_name = 'storage_files'
8
+
9
+ has_many :chunks, class_name: 'Dragonfly::ActiveRecord::Chunk', autosave: true, dependent: :delete_all, inverse_of: :file
10
+
11
+ serialize :metadata
12
+ validates_presence_of :metadata
13
+ validates_presence_of :accessed_at
14
+
15
+ before_validation :set_defaults
16
+
17
+ # default_value_for(:metadata) { Hash.new }
18
+ # default_value_for(:accessed_at) { Time.current }
19
+
20
+ # BLOB is typically 65k maximum, but in our case
21
+ # there's a 4/3 overhead for Base64 encoding, and up to 1% overhead
22
+ # for worst case GZip compression.
23
+ MAX_CHUNK_SIZE = 32_768
24
+
25
+ def data=(data)
26
+ self.chunks.each(&:mark_for_destruction)
27
+ (data.length / MAX_CHUNK_SIZE + 1).times do |index|
28
+ chunk = data[index * MAX_CHUNK_SIZE, MAX_CHUNK_SIZE]
29
+ self.chunks.new(data:chunk, idx:index)
30
+ end
31
+ end
32
+
33
+ def data
34
+ self.chunks.order(:idx).map(&:data).join
35
+ end
36
+
37
+ private
38
+
39
+ def set_defaults
40
+ self.metadata ||= Hash.new
41
+ self.accessed_at ||= Time.current
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,27 @@
1
+ require 'dragonfly-activerecord'
2
+
3
+ module Dragonfly::ActiveRecord
4
+ module Migration
5
+ def up
6
+ create_table :storage_chunks do |t|
7
+ t.integer :file_id
8
+ t.integer :idx
9
+ t.binary :encoded_data, limit: 65_536
10
+ end
11
+
12
+ add_index :storage_chunks, :file_id, using: 'hash'
13
+
14
+ create_table :storage_files do |t|
15
+ t.text :metadata
16
+ t.datetime :accessed_at
17
+ t.timestamps
18
+ end
19
+ end
20
+
21
+ def down
22
+ drop_table :storage_chunks
23
+ drop_table :storage_files
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,30 @@
1
+ require 'dragonfly-activerecord'
2
+ require 'dragonfly-activerecord/file'
3
+ require 'active_record'
4
+
5
+ module Dragonfly::ActiveRecord
6
+ class Store
7
+
8
+ # +temp_object+ should respond to +data+ and +meta+
9
+ def write(temp_object, opts={})
10
+ File.transaction do
11
+ file = File.create!(metadata: temp_object.meta)
12
+ file.data = temp_object.data
13
+ file.save!
14
+ return file.id.to_s
15
+ end
16
+ end
17
+
18
+ def read(uid)
19
+ file = File.find(uid.to_i)
20
+ file.update_attributes!(accessed_at: Time.now)
21
+ [ file.data, file.metadata ]
22
+ rescue ActiveRecord::RecordNotFound
23
+ nil
24
+ end
25
+
26
+ def destroy(uid)
27
+ File.destroy(uid.to_i)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module Dragonfly
2
+ module ActiveRecord
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require "dragonfly-activerecord/version"
2
+
3
+ module Dragonfly
4
+ module ActiveRecord
5
+ end
6
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ require 'dragonfly-activerecord/migration'
3
+
4
+ describe Dragonfly::ActiveRecord::Migration do
5
+ subject do
6
+ Class.new(ActiveRecord::Migration) do
7
+ include Dragonfly::ActiveRecord::Migration
8
+ end
9
+ end
10
+
11
+ it 'is a proper migration' do
12
+ subject.ancestors.should include(ActiveRecord::Migration)
13
+ end
14
+
15
+ it 'applies cleanly' do
16
+ silence_stream(STDOUT) { subject.new.up }
17
+ end
18
+
19
+ it 'rolls back cleanly' do
20
+ silence_stream(STDOUT) { subject.new.up ; subject.new.down }
21
+ end
22
+
23
+ context 'when applied' do
24
+ let(:model_class) { Class.new(ActiveRecord::Base) }
25
+
26
+ before do
27
+ silence_stream(STDOUT) { subject.new.up }
28
+ end
29
+
30
+ it 'result in a functional chunks model' do
31
+ model_class.table_name = 'storage_chunks'
32
+ model_class.create(file_id: 123, idx: 456, encoded_data: 'foobar')
33
+ model_class.count.should == 1
34
+ end
35
+
36
+ it 'result in a functional files model' do
37
+ model_class.table_name = 'storage_files'
38
+ model_class.create(metadata: 'foobar', accessed_at: Time.now)
39
+ model_class.count.should == 1
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+ require 'dragonfly-activerecord/store.rb'
3
+
4
+ describe Dragonfly::ActiveRecord::Store do
5
+ FakeFile = Struct.new(:data, :meta)
6
+
7
+ let(:fake_file) { FakeFile.new data, metadata }
8
+ let(:metadata) { {a:1} }
9
+
10
+ before { prepare_database }
11
+
12
+ share_examples_for 'store and retrieve' do
13
+ it 'retrieves the data' do
14
+ id = subject.write(fake_file)
15
+ returned_data, returned_meta = subject.read(id)
16
+
17
+ returned_data.length.should == data.length
18
+ returned_data.should == data
19
+ end
20
+ end
21
+
22
+
23
+ context 'for small chunks of text data' do
24
+ let(:data) { "foobar" }
25
+ it_should_behave_like 'store and retrieve'
26
+ end
27
+
28
+ context 'for small chunks of binary data' do
29
+ let(:data) { SecureRandom.random_bytes(64) }
30
+ it_should_behave_like 'store and retrieve'
31
+ end
32
+
33
+ context 'for large chunks of binary data' do
34
+ let(:data) { SecureRandom.random_bytes(2_000_000) }
35
+ it_should_behave_like 'store and retrieve'
36
+ end
37
+
38
+ it 'returns nil for missing files' do
39
+ subject.read('1337').should be_nil
40
+ end
41
+ end
data/spec/meta_spec.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ # This tests our RSpec setup works
3
+
4
+ describe 'Test suite' do
5
+ it 'has a working ActiveRecord connection' do
6
+ ActiveRecord::Base.connection.execute('SELECT(1)')
7
+ end
8
+ end
@@ -0,0 +1,78 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require 'dragonfly-activerecord/migration'
9
+ require 'active_record'
10
+
11
+ DATABASE = Pathname.new 'test.sqlite3'
12
+
13
+ def get_connection_hash
14
+ case ENV.fetch('DAR_ADAPTER', 'sqlite3mem')
15
+ when 'postgresql'
16
+ {
17
+ :adapter => 'postgresql',
18
+ :database => 'dar_test',
19
+ :host => 'localhost',
20
+ :min_messages => 'warning',
21
+ :username => ENV['DAR_DB_USER']
22
+ }
23
+ when 'mysql'
24
+ {
25
+ :adapter => 'mysql2',
26
+ :database => 'dar_test',
27
+ :host => 'localhost',
28
+ :username => ENV['DAR_DB_USER']
29
+ }
30
+ when 'sqlite3'
31
+ {
32
+ :adapter => 'sqlite3',
33
+ :database => DATABASE.to_s
34
+ }
35
+ when 'sqlite3mem'
36
+ {
37
+ :adapter => 'sqlite3',
38
+ :database => ':memory:'
39
+ }
40
+ end
41
+ end
42
+
43
+
44
+ class TestMigration < ActiveRecord::Migration
45
+ include Dragonfly::ActiveRecord::Migration
46
+ end
47
+
48
+ RSpec.configure do |config|
49
+ config.treat_symbols_as_metadata_keys_with_true_values = true
50
+ config.run_all_when_everything_filtered = true
51
+ config.filter_run :focus
52
+
53
+ # Run specs in random order to surface order dependencies. If you find an
54
+ # order dependency and want to debug it, you can fix the order by providing
55
+ # the seed, which is printed after each run.
56
+ # --seed 1234
57
+ config.order = 'random'
58
+
59
+
60
+ config.before(:each) do
61
+ # Connect to & cleanup test database
62
+ ActiveRecord::Base.establish_connection(get_connection_hash)
63
+
64
+ %w(storage_files storage_chunks).each do |table_name|
65
+ ActiveRecord::Base.connection.execute "DROP TABLE IF EXISTS #{table_name};"
66
+ end
67
+
68
+ def prepare_database
69
+ silence_stream(STDOUT) do
70
+ TestMigration.new.up
71
+ end
72
+ end
73
+ end
74
+
75
+ config.after(:each) do
76
+ DATABASE.delete if DATABASE.exist?
77
+ end
78
+ end
metadata ADDED
@@ -0,0 +1,219 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dragonfly-activerecord
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Julien Letessier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
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: 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
+ - !ruby/object:Gem::Dependency
56
+ name: appraisal
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pg
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
+ - !ruby/object:Gem::Dependency
98
+ name: mysql2
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: activerecord
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: 3.2.6
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: 3.2.6
153
+ description: ActiveRecord-backed data store for Dragonfly
154
+ email:
155
+ - julien.letessier@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - .gitignore
161
+ - .rspec
162
+ - .ruby-version
163
+ - .travis.yml
164
+ - Appraisals
165
+ - Gemfile
166
+ - Guardfile
167
+ - LICENSE.txt
168
+ - README.md
169
+ - Rakefile
170
+ - dragonfly-activerecord.gemspec
171
+ - gemfiles/rails32.gemfile
172
+ - gemfiles/rails32.gemfile.lock
173
+ - gemfiles/rails40.gemfile
174
+ - gemfiles/rails40.gemfile.lock
175
+ - gemfiles/rails40_mysql.gemfile
176
+ - gemfiles/rails40_mysql.gemfile.lock
177
+ - gemfiles/rails40_pg.gemfile
178
+ - gemfiles/rails40_pg.gemfile.lock
179
+ - gemfiles/rails40_sqlite.gemfile
180
+ - gemfiles/rails40_sqlite.gemfile.lock
181
+ - lib/dragonfly-activerecord.rb
182
+ - lib/dragonfly-activerecord/chunk.rb
183
+ - lib/dragonfly-activerecord/file.rb
184
+ - lib/dragonfly-activerecord/migration.rb
185
+ - lib/dragonfly-activerecord/store.rb
186
+ - lib/dragonfly-activerecord/version.rb
187
+ - spec/dragonfly-activerecord/migration_spec.rb
188
+ - spec/dragonfly-activerecord/store_spec.rb
189
+ - spec/meta_spec.rb
190
+ - spec/spec_helper.rb
191
+ homepage: https://github.com/mezis/dragonfly-activerecord
192
+ licenses:
193
+ - MIT
194
+ metadata: {}
195
+ post_install_message:
196
+ rdoc_options: []
197
+ require_paths:
198
+ - lib
199
+ required_ruby_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - '>='
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ required_rubygems_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - '>='
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ requirements: []
210
+ rubyforge_project:
211
+ rubygems_version: 2.0.14
212
+ signing_key:
213
+ specification_version: 4
214
+ summary: ActiveRecord-backed data store for Dragonfly
215
+ test_files:
216
+ - spec/dragonfly-activerecord/migration_spec.rb
217
+ - spec/dragonfly-activerecord/store_spec.rb
218
+ - spec/meta_spec.rb
219
+ - spec/spec_helper.rb