carrierwave-postgresql-table 0.1.1 → 0.1.2

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: 5ef806ccfb8914f80bcbe80cdd3ebd8faa89cd7c
4
- data.tar.gz: 0ab0e9e7757bb7c0767aa375ea55dceda7b2ac03
3
+ metadata.gz: 764a5c85b7937568cc214e4ba49dd3bbac7ccdef
4
+ data.tar.gz: 1800fb54ffcd1e5518db1afe702fa6353696c2b2
5
5
  SHA512:
6
- metadata.gz: cca0e9d3e00674e05e7c224154d225706653393160210c3ae1bc1920ede30840316aa032aef256cf532b47abd89b9770bb25869baf6073300d1845696fda7c7c
7
- data.tar.gz: 1d74a9ee0a82fdda54485fffd8cee3c2aa06f84197861ff2941119216fa5c3fa2395aae706253067f8e80c586d9f263b16d8cba0a76e0f72abb8f56548d13e1c
6
+ metadata.gz: 8a73a0cb83935b7359fde2b33717050aecbefe7b39417d57806c555500e9c131f02067da4560bb079a47febfc22a7327d62c6f825c7f96cd6f5c1211ca894324
7
+ data.tar.gz: 50caf0ae944e1e96260c066f0769bcf18965a36e6c72d146b94ff9d54001dcdf6e428a2786b0ae313302c7a6c80540271607412a96b78a91a354c4e1cf7dc088
data/circle.yml CHANGED
@@ -5,7 +5,8 @@ dependencies:
5
5
  - bundle exec appraisal install
6
6
  database:
7
7
  override:
8
- - psql -c "CREATE DATABASE carrierwave_postgresql_table_test;" -U postgres
8
+ - psql -c "CREATE USER carrierwave_postgresql_table_test WITH PASSWORD '';" -U postgres
9
+ - psql -c "CREATE DATABASE carrierwave_postgresql_table_test OWNER carrierwave_postgresql_table_test;" -U postgres
9
10
  test:
10
11
  override:
11
12
  - bundle exec appraisal rake
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- carrierwave-postgresql-table (0.1.0)
4
+ carrierwave-postgresql-table (0.1.2)
5
5
  activerecord
6
6
  carrierwave
7
7
  pg
@@ -132,4 +132,4 @@ DEPENDENCIES
132
132
  rake (~> 10.0)
133
133
 
134
134
  BUNDLED WITH
135
- 1.13.0
135
+ 1.13.1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- carrierwave-postgresql-table (0.1.0)
4
+ carrierwave-postgresql-table (0.1.2)
5
5
  activerecord
6
6
  carrierwave
7
7
  pg
@@ -129,4 +129,4 @@ DEPENDENCIES
129
129
  rake (~> 10.0)
130
130
 
131
131
  BUNDLED WITH
132
- 1.13.0
132
+ 1.13.1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- carrierwave-postgresql-table (0.1.0)
4
+ carrierwave-postgresql-table (0.1.2)
5
5
  activerecord
6
6
  carrierwave
7
7
  pg
@@ -134,4 +134,4 @@ DEPENDENCIES
134
134
  rake (~> 10.0)
135
135
 
136
136
  BUNDLED WITH
137
- 1.13.0
137
+ 1.13.1
@@ -1,5 +1,5 @@
1
1
  module CarrierWave
2
2
  module PostgresqlTable
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -71,7 +71,7 @@ module CarrierWave
71
71
  data = raw_connection.lo_read(lo, length)
72
72
  @read_pos = raw_connection.lo_tell(lo)
73
73
  else
74
- data = raw_connection.lo_read(lo, size)
74
+ data = raw_connection.lo_read(lo, self.size)
75
75
  end
76
76
  ensure
77
77
  raw_connection.lo_close(lo) if(lo)
@@ -88,6 +88,7 @@ module CarrierWave
88
88
  def to_tempfile
89
89
  Tempfile.new(:binmode => true).tap do |tempfile|
90
90
  IO.copy_stream(self, tempfile)
91
+ self.rewind
91
92
  tempfile.rewind
92
93
  tempfile.fsync
93
94
  end
@@ -102,7 +103,15 @@ module CarrierWave
102
103
  end
103
104
 
104
105
  def size
105
- @record.size
106
+ @size = @record.size || fetch_size
107
+ end
108
+
109
+ def eof?
110
+ @read_pos == self.size
111
+ end
112
+
113
+ def rewind
114
+ @read_pos = 0
106
115
  end
107
116
 
108
117
  def content_type
@@ -123,23 +132,23 @@ module CarrierWave
123
132
  raw_connection = connection.raw_connection
124
133
  oid = nil
125
134
  if(new_file.kind_of?(CarrierWave::Storage::PostgresqlTable::File))
126
- oid = new_file.copy_to(@path)
135
+ file = new_file
127
136
  else
128
137
  file = new_file.to_file
138
+ end
129
139
 
130
- begin
131
- oid = @record.pg_largeobject_oid || raw_connection.lo_creat
132
- handle = raw_connection.lo_open(oid, PG::INV_WRITE)
133
- raw_connection.lo_truncate(handle, 0)
134
- buffer = ""
135
- until file.eof?
136
- file.read(READ_CHUNK_SIZE, buffer)
137
- raw_connection.lo_write(handle, buffer)
138
- end
139
- file.close
140
- ensure
141
- raw_connection.lo_close(handle)
140
+ begin
141
+ oid = @record.pg_largeobject_oid || raw_connection.lo_creat
142
+ handle = raw_connection.lo_open(oid, PG::INV_WRITE)
143
+ raw_connection.lo_truncate(handle, 0)
144
+ buffer = ""
145
+ until file.eof?
146
+ file.read(READ_CHUNK_SIZE, buffer)
147
+ raw_connection.lo_write(handle, buffer)
142
148
  end
149
+ file.rewind
150
+ ensure
151
+ raw_connection.lo_close(handle)
143
152
  end
144
153
 
145
154
  begin
@@ -164,26 +173,6 @@ module CarrierWave
164
173
  end
165
174
  end
166
175
 
167
- def copy_to(new_path)
168
- CarrierWaveFile.transaction do
169
- connection = CarrierWaveFile.connection
170
-
171
- result = connection.execute("INSERT INTO pg_largeobject_metadata(lomowner, lomacl)
172
- SELECT lomowner, lomacl
173
- FROM pg_largeobject_metadata
174
- WHERE oid = #{CarrierWaveFile.sanitize(@record.pg_largeobject_oid)}
175
- RETURNING oid AS new_oid")
176
- new_oid = Integer(result.values[0][0])
177
-
178
- connection.execute("INSERT INTO pg_largeobject(loid, pageno, data)
179
- SELECT #{new_oid}, pageno, data
180
- FROM pg_largeobject
181
- WHERE loid = #{CarrierWaveFile.sanitize(@record.pg_largeobject_oid)}")
182
-
183
- new_oid
184
- end
185
- end
186
-
187
176
  def move_to(new_path)
188
177
  CarrierWaveFile.transaction do
189
178
  # Remove any existing files at the current path.
@@ -197,6 +186,19 @@ module CarrierWave
197
186
  def delete
198
187
  CarrierWaveFile.delete_all_files("id = #{CarrierWaveFile.sanitize(@record.id)}")
199
188
  end
189
+
190
+ private
191
+
192
+ def fetch_size
193
+ size = nil
194
+ CarrierWaveFile.transaction do
195
+ raw_connection = CarrierWaveFile.connection.raw_connection
196
+ lo = raw_connection.lo_open(@record.pg_largeobject_oid)
197
+ size = raw_connection.lo_lseek(lo, 0, PG::SEEK_END)
198
+ end
199
+
200
+ size
201
+ end
200
202
  end
201
203
  end
202
204
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-postgresql-table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Muerdter
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-25 00:00:00.000000000 Z
11
+ date: 2016-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord