dragonfly-activerecord 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 804ea5bfdd90237f08a7c477f0b0019e040648c8
4
- data.tar.gz: 3ef8c72e9b1aea1e513400751f39369acf91647c
3
+ metadata.gz: c0b2e1ead6f33913d7bd6ea10f849327206ff368
4
+ data.tar.gz: 159786b1cc1b7b9992f0b1922d1b40c80dd0627e
5
5
  SHA512:
6
- metadata.gz: 04dcc1651721230e8d937252fc08045f2b4e16afaf5359ff82408da7ac313a532f8ee9b18785ffe9b74d52414fe58594b5af2d0d88f4d7f425aea9c89a741b3b
7
- data.tar.gz: 4cb3cd91cce1c350174cee6d4b91836d673ad33ece38f107884df2cc04651a4c77e073d119f02f74be912dad601ad4759ab5d3726a6400e2d4afd36bb56af519
6
+ metadata.gz: 15b52b9146902030d0d8c563fe2f760fd28fb69d795e0a7e4cb60407199c75fc8347ef064378325a593dcd8971f73aa41c326e16f0b0013bc09292b739e59541
7
+ data.tar.gz: 8bf1c426ba915ceb724df52e9818e33677180647b05c967a7dac9159a23cf4cfab44788a4b874979b1f6a36ae5e52074715bc8261468b3e066f99e2f563b10c3
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "rebund"]
2
+ path = rebund
3
+ url = https://github.com/mezis/rebund.git
data/.travis.yml CHANGED
@@ -10,8 +10,15 @@ gemfile:
10
10
  - gemfiles/rails40.gemfile
11
11
  before_install:
12
12
  - gem update bundler
13
- - bundle install
14
- bundler_args:
13
+ install:
14
+ - ./rebund/run download
15
+ - bundle install --path ../vendor/bundle
16
+ after_script:
17
+ - ./rebund/run upload
15
18
  before_script:
16
19
  - psql -c 'create database dar_test;' -U postgres
17
20
  - mysql -e 'create database dar_test;'
21
+ env:
22
+ global:
23
+ - secure: "hAzED2sL+PgYtqNCd46gxW15+kiMOW5LRHj5oK2zhY6rtU/efQ9hg7zt4h9zjFtk142R3D6XOMqlXAmJ6zZ/mWcd+5qwD52v6Qp/r8jJTFhXmYSIKW2MAKUbK51bxERkN5OUeZx7lLBC4BIImAue+PsTORMHtA2NJSROAnz573Y="
24
+
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dragonfly-activerecord (0.0.2)
4
+ dragonfly-activerecord (0.1.0)
5
5
  activerecord (>= 3.2.6)
6
+ dragonfly (>= 1.0.2)
6
7
 
7
8
  GEM
8
9
  remote: http://yarp.dev/
@@ -32,6 +33,9 @@ GEM
32
33
  timers (~> 1.1.0)
33
34
  coderay (1.1.0)
34
35
  diff-lcs (1.2.5)
36
+ dragonfly (1.0.2)
37
+ multi_json (~> 1.0)
38
+ rack
35
39
  ffi (1.9.3)
36
40
  formatador (0.2.4)
37
41
  guard (2.2.5)
@@ -58,6 +62,7 @@ GEM
58
62
  coderay (~> 1.0)
59
63
  method_source (~> 0.8)
60
64
  slop (~> 3.4)
65
+ rack (1.5.2)
61
66
  rake (10.1.1)
62
67
  rb-fsevent (0.9.4)
63
68
  rb-inotify (0.9.3)
data/Guardfile CHANGED
@@ -1,7 +1,7 @@
1
1
  # A sample Guardfile
2
2
  # More info at https://github.com/guard/guard#readme
3
3
 
4
- guard :rspec do
4
+ guard :rspec, cmd: 'bundle exec rspec' do
5
5
  watch(%r{^spec/.+_spec\.rb$})
6
6
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
7
  watch('spec/spec_helper.rb') { "spec" }
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency 'guard-rspec'
30
30
 
31
31
  spec.add_dependency 'activerecord', '>= 3.2.6'
32
+ spec.add_dependency 'dragonfly', '>= 1.0.2'
32
33
  end
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: /Users/mezis/Dropbox/Development/dragonfly-activerecord
3
3
  specs:
4
- dragonfly-activerecord (0.0.1)
4
+ dragonfly-activerecord (0.1.0)
5
5
  activerecord (>= 3.2.6)
6
+ dragonfly (>= 1.0.2)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -27,6 +28,9 @@ GEM
27
28
  timers (~> 1.1.0)
28
29
  coderay (1.1.0)
29
30
  diff-lcs (1.2.5)
31
+ dragonfly (1.0.2)
32
+ multi_json (~> 1.0)
33
+ rack
30
34
  ffi (1.9.3)
31
35
  formatador (0.2.4)
32
36
  guard (2.2.4)
@@ -52,6 +56,7 @@ GEM
52
56
  coderay (~> 1.0)
53
57
  method_source (~> 0.8)
54
58
  slop (~> 3.4)
59
+ rack (1.5.2)
55
60
  rake (10.1.1)
56
61
  rb-fsevent (0.9.3)
57
62
  rb-inotify (0.9.2)
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: /Users/mezis/Dropbox/Development/dragonfly-activerecord
3
3
  specs:
4
- dragonfly-activerecord (0.0.1)
4
+ dragonfly-activerecord (0.1.0)
5
5
  activerecord (>= 3.2.6)
6
+ dragonfly (>= 1.0.2)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -32,6 +33,9 @@ GEM
32
33
  timers (~> 1.1.0)
33
34
  coderay (1.1.0)
34
35
  diff-lcs (1.2.5)
36
+ dragonfly (1.0.2)
37
+ multi_json (~> 1.0)
38
+ rack
35
39
  ffi (1.9.3)
36
40
  formatador (0.2.4)
37
41
  guard (2.2.4)
@@ -58,6 +62,7 @@ GEM
58
62
  coderay (~> 1.0)
59
63
  method_source (~> 0.8)
60
64
  slop (~> 3.4)
65
+ rack (1.5.2)
61
66
  rake (10.1.1)
62
67
  rb-fsevent (0.9.3)
63
68
  rb-inotify (0.9.2)
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: /Users/mezis/Dropbox/Development/dragonfly-activerecord
3
3
  specs:
4
- dragonfly-activerecord (0.0.1)
4
+ dragonfly-activerecord (0.1.0)
5
5
  activerecord (>= 3.2.6)
6
+ dragonfly (>= 1.0.2)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -32,6 +33,9 @@ GEM
32
33
  timers (~> 1.1.0)
33
34
  coderay (1.1.0)
34
35
  diff-lcs (1.2.5)
36
+ dragonfly (1.0.2)
37
+ multi_json (~> 1.0)
38
+ rack
35
39
  ffi (1.9.3)
36
40
  formatador (0.2.4)
37
41
  guard (2.2.4)
@@ -58,6 +62,7 @@ GEM
58
62
  coderay (~> 1.0)
59
63
  method_source (~> 0.8)
60
64
  slop (~> 3.4)
65
+ rack (1.5.2)
61
66
  rake (10.1.1)
62
67
  rb-fsevent (0.9.3)
63
68
  rb-inotify (0.9.2)
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: /Users/mezis/Dropbox/Development/dragonfly-activerecord
3
3
  specs:
4
- dragonfly-activerecord (0.0.1)
4
+ dragonfly-activerecord (0.1.0)
5
5
  activerecord (>= 3.2.6)
6
+ dragonfly (>= 1.0.2)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -32,6 +33,9 @@ GEM
32
33
  timers (~> 1.1.0)
33
34
  coderay (1.1.0)
34
35
  diff-lcs (1.2.5)
36
+ dragonfly (1.0.2)
37
+ multi_json (~> 1.0)
38
+ rack
35
39
  ffi (1.9.3)
36
40
  formatador (0.2.4)
37
41
  guard (2.2.4)
@@ -58,6 +62,7 @@ GEM
58
62
  coderay (~> 1.0)
59
63
  method_source (~> 0.8)
60
64
  slop (~> 3.4)
65
+ rack (1.5.2)
61
66
  rake (10.1.1)
62
67
  rb-fsevent (0.9.3)
63
68
  rb-inotify (0.9.2)
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: /Users/mezis/Dropbox/Development/dragonfly-activerecord
3
3
  specs:
4
- dragonfly-activerecord (0.0.1)
4
+ dragonfly-activerecord (0.1.0)
5
5
  activerecord (>= 3.2.6)
6
+ dragonfly (>= 1.0.2)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -32,6 +33,9 @@ GEM
32
33
  timers (~> 1.1.0)
33
34
  coderay (1.1.0)
34
35
  diff-lcs (1.2.5)
36
+ dragonfly (1.0.2)
37
+ multi_json (~> 1.0)
38
+ rack
35
39
  ffi (1.9.3)
36
40
  formatador (0.2.4)
37
41
  guard (2.2.4)
@@ -58,6 +62,7 @@ GEM
58
62
  coderay (~> 1.0)
59
63
  method_source (~> 0.8)
60
64
  slop (~> 3.4)
65
+ rack (1.5.2)
61
66
  rake (10.1.1)
62
67
  rb-fsevent (0.9.3)
63
68
  rb-inotify (0.9.2)
@@ -13,29 +13,46 @@ module Dragonfly::ActiveRecord
13
13
  validates_presence_of :accessed_at
14
14
 
15
15
  before_validation :set_defaults
16
-
17
- # default_value_for(:metadata) { Hash.new }
18
- # default_value_for(:accessed_at) { Time.current }
16
+ after_save :build_chunks
19
17
 
20
18
  # BLOB is typically 65k maximum, but in our case
21
19
  # there's a 4/3 overhead for Base64 encoding, and up to 1% overhead
22
20
  # for worst case GZip compression.
23
21
  MAX_CHUNK_SIZE = 32_768
24
22
 
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
23
+ # max number of chunks read at a time
24
+ MAX_CHUNK_READ = 10
25
+
26
+ def data=(file)
27
+ @_data = file
31
28
  end
32
29
 
33
30
  def data
34
- self.chunks.order(:idx).map(&:data).join
31
+ @_output ||= Tempfile.new('dar', encoding: 'binary').tap do |fd|
32
+ index = 0
33
+ while true
34
+ range = index...(index + MAX_CHUNK_READ)
35
+ chunklist = chunks.where(idx:range).to_a.sort_by(&:idx)
36
+ break if chunklist.empty?
37
+ chunklist.each { |chunk| fd.write(chunk.data) }
38
+ index += MAX_CHUNK_READ
39
+ end
40
+ fd.rewind
41
+ end
35
42
  end
36
43
 
37
44
  private
38
45
 
46
+ def build_chunks
47
+ # require 'pry' ; binding.pry
48
+ chunks.delete_all
49
+ index = 0
50
+ while chunk = @_data.read(MAX_CHUNK_SIZE)
51
+ chunks.create!(data:chunk, idx:index)
52
+ index += 1
53
+ end
54
+ end
55
+
39
56
  def set_defaults
40
57
  self.metadata ||= Hash.new
41
58
  self.accessed_at ||= Time.current
@@ -7,11 +7,13 @@ module Dragonfly::ActiveRecord
7
7
 
8
8
  # +temp_object+ should respond to +data+ and +meta+
9
9
  def write(temp_object, opts={})
10
- File.new.tap do |file|
11
- file.metadata = temp_object.meta
12
- file.data = temp_object.data
13
- file.save!
14
- return file.id.to_s
10
+ temp_object.file do |fd|
11
+ File.new.tap do |file|
12
+ file.metadata = temp_object.meta
13
+ file.data = fd
14
+ file.save!
15
+ return file.id.to_s
16
+ end
15
17
  end
16
18
  end
17
19
 
@@ -1,5 +1,5 @@
1
1
  module Dragonfly
2
2
  module ActiveRecord
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -1,10 +1,16 @@
1
1
  require 'spec_helper'
2
2
  require 'dragonfly-activerecord/store.rb'
3
+ require 'dragonfly'
3
4
 
4
5
  describe Dragonfly::ActiveRecord::Store do
5
- FakeFile = Struct.new(:data, :meta)
6
6
 
7
- let(:fake_file) { FakeFile.new data, metadata }
7
+ let(:fake_file) do
8
+ Dragonfly::Content.new(
9
+ nil, # no app
10
+ Dragonfly::TempObject.new(data),
11
+ metadata)
12
+ end
13
+
8
14
  let(:metadata) { {a:1} }
9
15
 
10
16
  before { prepare_database }
@@ -15,7 +21,7 @@ describe Dragonfly::ActiveRecord::Store do
15
21
  returned_data, returned_meta = subject.read(id)
16
22
 
17
23
  returned_data.length.should == data.length
18
- returned_data.should == data
24
+ returned_data.read.should == data
19
25
  end
20
26
  end
21
27
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dragonfly-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Letessier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-04 00:00:00.000000000 Z
11
+ date: 2014-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: 3.2.6
153
+ - !ruby/object:Gem::Dependency
154
+ name: dragonfly
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: 1.0.2
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: 1.0.2
153
167
  description: ActiveRecord-backed data store for Dragonfly
154
168
  email:
155
169
  - julien.letessier@gmail.com
@@ -158,6 +172,7 @@ extensions: []
158
172
  extra_rdoc_files: []
159
173
  files:
160
174
  - .gitignore
175
+ - .gitmodules
161
176
  - .rspec
162
177
  - .ruby-version
163
178
  - .travis.yml