s3_relay 0.1.0 → 0.2.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: f09dca34c033813548f7fd621fd2cb57c8979a7b
4
- data.tar.gz: eaacf64ab7bbc521f3899bc345f9df23f57ca06e
3
+ metadata.gz: 7eb3749db208e34c25730efc1bac3cdaa60cbbca
4
+ data.tar.gz: 5ab8beaaa957f5abcf41f687d82e2f7c06deea37
5
5
  SHA512:
6
- metadata.gz: 77466db42281a43c75f81640408528e2ba01e026f04498daef1d0d204e4a551c86bea0d70131a4b7c7f0e39546a5def1f672df8cfa7a648b808f4022f2c100cd
7
- data.tar.gz: 66818a2437cbbbd091ff420c7914233dc320358251ad51ea49270aa0a1f271ab95a6e237f16965aa8e0b1fec9acf821d9a642dc107e6f848ca8a1b2ddc2448b6
6
+ metadata.gz: 4d6166f156b612b5619c355a19b42ede0dc6572505cd301985916c809ac6822729dd30c92a58a25bb92fc14a10d3f2cc01047ad305372abc1b31e3d101a03b22
7
+ data.tar.gz: 28f2e274966d3a849afaa2ecbaaca004c28f7de45d7fd35b9c95da668c1a0a54cec1e83d6e9253f5c56217357fca44f28e82ebcf4dc575a2dcea2aeda22ba23e
data/README.md CHANGED
@@ -147,7 +147,9 @@ option like so:
147
147
  <%= s3_relay_field @artist, :mp3_uploads, multiple: true, disposition: "attachment" %>
148
148
  ```
149
149
 
150
- ### Process uploads asynchronously
150
+ ### Importing files
151
+
152
+ #### Processing uploads asynchronously
151
153
 
152
154
  Use your background job processor of choice to process uploads pending
153
155
  ingestion (and image processing) by your app.
@@ -155,25 +157,52 @@ ingestion (and image processing) by your app.
155
157
  Say you're using [Resque](https://github.com/resque/resque) and [CarrierWave](https://github.com/carrierwaveuploader/carrierwave), you could define a job class:
156
158
 
157
159
  ```ruby
158
- class ProductPhotoImporter
160
+ class ProductPhoto::Import
159
161
  @queue = :photo_import
160
162
 
161
- def self.perform(product_id)
162
- @product = Product.find(id)
163
+ def self.perform(product_id, upload_id)
164
+ @product = Product.find(product_id)
165
+ @upload = S3Relay::Upload.find(upload_id)
163
166
 
164
- @product.photo_uploads.pending.each do |upload|
165
- @product.photos.create(remote_file_url: upload.private_url)
166
- upload.mark_imported!
167
- end
167
+ @product.photos.create!(remote_file_url: @upload.private_url)
168
+ @upload.mark_imported!
168
169
  end
169
170
  end
170
171
  ```
171
172
 
172
- Then, enqueue a job from your controller, callback, service object, etc.
173
- whenever there may be new uploads to process:
173
+ #### Triggering upload imports for existing parent objects
174
+
175
+ If you would like to immediately enqueue a job to begin importing an upload
176
+ into its final desination, simply define a method on your parent object
177
+ called `import_upload` and that method will be called after an `S3Relay::Upload`
178
+ is created.
179
+
180
+ #### Triggering upload imports for new parent objects
181
+
182
+ If you would like to immediately enqueue a job to begin importing all of the
183
+ uploads for a new parent object following its creation, you might want to setup
184
+ a callback to enqueue those imports.
185
+
186
+ #### Examples
174
187
 
175
188
  ```ruby
176
- Resque.enqueue(ProductPhotoImporter, product.id)
189
+ class Product
190
+
191
+ # Called by s3_relay when an associated S3Relay::Upload object is created
192
+ def import_upload(upload_id)
193
+ Resque.enqueue(ProductPhoto::Import, id, upload_id)
194
+ end
195
+
196
+ after_commit :import_uploads, on: :create
197
+
198
+ # Called via after_commit to enqueue imports of S3Relay::Upload objects
199
+ def import_uploads
200
+ photo_uploads.pending.each do |upload|
201
+ Resque.enqueue(ProductPhoto::Import, id, upload.id)
202
+ end
203
+ end
204
+
205
+ end
177
206
  ```
178
207
 
179
208
  ### Restricting the objects uploads can be associated with
@@ -4,6 +4,11 @@ displayFailedUpload = (progressColumn=null) ->
4
4
  else
5
5
  alert("File could not be uploaded")
6
6
 
7
+ publishEvent = (name, detail) ->
8
+ ev = document.createEvent "CustomEvent"
9
+ ev.initCustomEvent name, true, false, detail
10
+ document.dispatchEvent ev
11
+
7
12
  saveUrl = (container, uuid, filename, contentType, publicUrl) ->
8
13
  privateUrl = null
9
14
 
@@ -21,6 +26,7 @@ saveUrl = (container, uuid, filename, contentType, publicUrl) ->
21
26
  public_url: publicUrl
22
27
  success: (data, status, xhr) ->
23
28
  privateUrl = data.private_url
29
+ publishEvent "upload:success", { uuid: uuid }
24
30
  error: (xhr) ->
25
31
  console.log xhr.responseText
26
32
 
@@ -1,3 +1,3 @@
1
1
  module S3Relay
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3_relay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenny Johnston
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-02 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coffee-rails
@@ -212,8 +212,6 @@ files:
212
212
  - test/dummy/config/secrets.yml
213
213
  - test/dummy/db/migrate/20141021002149_create_products.rb
214
214
  - test/dummy/db/schema.rb
215
- - test/dummy/log/development.log
216
- - test/dummy/log/test.log
217
215
  - test/dummy/public/404.html
218
216
  - test/dummy/public/422.html
219
217
  - test/dummy/public/500.html
@@ -247,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
247
245
  version: '0'
248
246
  requirements: []
249
247
  rubyforge_project:
250
- rubygems_version: 2.4.5
248
+ rubygems_version: 2.4.3
251
249
  signing_key:
252
250
  specification_version: 4
253
251
  summary: Direct uploads to S3 and ingestion by your Rails app.
@@ -283,8 +281,6 @@ test_files:
283
281
  - test/dummy/config.ru
284
282
  - test/dummy/db/migrate/20141021002149_create_products.rb
285
283
  - test/dummy/db/schema.rb
286
- - test/dummy/log/development.log
287
- - test/dummy/log/test.log
288
284
  - test/dummy/public/404.html
289
285
  - test/dummy/public/422.html
290
286
  - test/dummy/public/500.html
@@ -1,53 +0,0 @@
1
-  (6.8ms) CREATE TABLE "schema_migrations" ("version" character varying(255) NOT NULL) 
2
-  (3.9ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
3
- ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
4
- Migrating to CreateS3RelayUploads (20141009000804)
5
-  (0.1ms) BEGIN
6
-  (5.3ms) CREATE TABLE "s3_relay_uploads" ("id" serial primary key, "parent_type" character varying(255), "parent_id" integer, "uuid" bytea, "filename" text, "content_type" character varying(255), "state" character varying(255), "data" json DEFAULT '{}', "uploaded_at" timestamp, "imported_at" timestamp, "created_at" timestamp, "updated_at" timestamp) 
7
- SQL (0.6ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20141009000804"]]
8
-  (0.5ms) COMMIT
9
- ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
10
-  (5.7ms) CREATE TABLE "schema_migrations" ("version" character varying(255) NOT NULL) 
11
-  (1.6ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
12
- ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
13
- Migrating to CreateS3RelayUploads (20141009000804)
14
-  (0.1ms) BEGIN
15
-  (3.8ms) CREATE TABLE "s3_relay_uploads" ("id" serial primary key, "parent_type" character varying(255), "parent_id" integer, "uuid" bytea, "filename" text, "content_type" character varying(255), "state" character varying(255), "data" json DEFAULT '{}', "pending_at" timestamp, "imported_at" timestamp, "created_at" timestamp, "updated_at" timestamp) 
16
- SQL (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20141009000804"]]
17
-  (0.6ms) COMMIT
18
- ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
19
- ActiveRecord::SchemaMigration Load (25.7ms) SELECT "schema_migrations".* FROM "schema_migrations"
20
- Migrating to CreateProducts (20141021002149)
21
-  (0.2ms) BEGIN
22
-  (69.1ms) CREATE TABLE "products" ("id" serial primary key, "name" character varying(255), "created_at" timestamp, "updated_at" timestamp) 
23
- SQL (4.9ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20141021002149"]]
24
-  (5.7ms) COMMIT
25
- ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
26
-  (6.1ms) CREATE TABLE "schema_migrations" ("version" character varying(255) NOT NULL) 
27
-  (1.9ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
28
- ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
29
- Migrating to CreateS3RelayUploads (20141009000804)
30
-  (0.1ms) BEGIN
31
-  (4.7ms) CREATE TABLE "s3_relay_uploads" ("id" serial primary key, "uuid" bytea, "parent_type" character varying(255), "parent_id" integer, "upload_type" character varying(255), "filename" text, "content_type" character varying(255), "state" character varying(255), "data" json DEFAULT '{}', "pending_at" timestamp, "imported_at" timestamp, "created_at" timestamp, "updated_at" timestamp) 
32
- SQL (0.8ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20141009000804"]]
33
-  (0.8ms) COMMIT
34
- Migrating to CreateProducts (20141021002149)
35
-  (0.3ms) BEGIN
36
-  (5.1ms) CREATE TABLE "products" ("id" serial primary key, "name" character varying(255), "created_at" timestamp, "updated_at" timestamp) 
37
- SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20141021002149"]]
38
-  (0.6ms) COMMIT
39
- ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
40
-  (20.7ms) CREATE TABLE "schema_migrations" ("version" character varying(255) NOT NULL) 
41
-  (9.3ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
42
- ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
43
- Migrating to CreateS3RelayUploads (20141009000804)
44
-  (0.1ms) BEGIN
45
-  (24.8ms) CREATE TABLE "s3_relay_uploads" ("id" serial primary key, "uuid" bytea, "user_id" integer, "parent_type" character varying(255), "parent_id" integer, "upload_type" character varying(255), "filename" text, "content_type" character varying(255), "state" character varying(255), "data" json DEFAULT '{}', "pending_at" timestamp, "imported_at" timestamp, "created_at" timestamp, "updated_at" timestamp) 
46
- SQL (6.2ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20141009000804"]]
47
-  (6.0ms) COMMIT
48
- Migrating to CreateProducts (20141021002149)
49
-  (11.0ms) BEGIN
50
-  (9.0ms) CREATE TABLE "products" ("id" serial primary key, "name" character varying(255), "created_at" timestamp, "updated_at" timestamp) 
51
- SQL (1.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20141021002149"]]
52
-  (0.9ms) COMMIT
53
- ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"