file_blobs_rails 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/file_blobs_rails.gemspec +3 -2
- data/lib/file_blobs_rails/action_controller_data_streaming_extensions.rb +1 -23
- data/lib/file_blobs_rails/active_record_extensions.rb +1 -0
- data/lib/file_blobs_rails/active_record_table_definition_extensions.rb +7 -4
- data/test/active_record_extensions_test.rb +13 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 740e1bf80a4e98b59c77c3382b94a7c4b1ddb9f4
|
4
|
+
data.tar.gz: d45516a3846ffe72956a847f6f176e91c26d1e5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67a9a63c094a193b8a210c4a8a410063bf1e0e83650af47d7e320ecfefac5417e76c9aeb4964a3224cde3ebe48ce67b1769d2c0d648b15620a306a920a36f492
|
7
|
+
data.tar.gz: 5b517bd14377121de9a7513a23855b68663b39e978c5d1622b30d257be02aff52d83b3f4e633eea868e0592be700638e35939e71ae77721f03683100d38bde0a
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/file_blobs_rails.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: file_blobs_rails 0.2.
|
5
|
+
# stub: file_blobs_rails 0.2.2 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "file_blobs_rails"
|
9
|
-
s.version = "0.2.
|
9
|
+
s.version = "0.2.2"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
@@ -51,6 +51,7 @@ Gem::Specification.new do |s|
|
|
51
51
|
"lib/file_blobs_rails/generators/templates/file_blobs.yml.erb",
|
52
52
|
"lib/file_blobs_rails/generators/templates/files/invoice.pdf",
|
53
53
|
"lib/file_blobs_rails/generators/templates/files/ruby.png",
|
54
|
+
"test/active_record_extensions_test.rb",
|
54
55
|
"test/blob_model_test.rb",
|
55
56
|
"test/blob_owner_test.rb",
|
56
57
|
"test/controller_extensions_test.rb",
|
@@ -28,29 +28,7 @@ module ActionControllerDataStreamingExtensions
|
|
28
28
|
send_data proxy.data, send_options
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
32
|
-
# Creates the table used to hold file blobs.
|
33
|
-
#
|
34
|
-
# @param [Symbol] table_name the name of the table used to hold file data
|
35
|
-
# @param [Hash<Symbol, Object>] options
|
36
|
-
# @option options [Boolean] null true
|
37
|
-
# @option options [Integer] blob_limit the maximum file size that can be
|
38
|
-
# stored in the table; defaults to 1 megabyte
|
39
|
-
def file_blob(column_name_base = :file, options = {}, &block)
|
40
|
-
allow_null = options[:null] || false
|
41
|
-
mime_type_limit = options[:mime_type_limit] || 64
|
42
|
-
file_name_limit = options[:file_name_limit] || 256
|
43
|
-
|
44
|
-
# The index is needed for garbage-collection eligibility checks.
|
45
|
-
string :"#{column_name_base}_blob_id", limit: 48, null: allow_null,
|
46
|
-
index: true
|
47
|
-
|
48
|
-
integer :"#{column_name_base}_size", null: allow_null
|
49
|
-
string :"#{column_name_base}_mime_type", limit: mime_type_limit,
|
50
|
-
null: allow_null
|
51
|
-
string :"#{column_name_base}_original_name", limit: file_name_limit,
|
52
|
-
null: allow_null
|
53
|
-
end
|
31
|
+
protected :send_file_blob
|
54
32
|
end # module FileBlobs::ActionControllerDataStreamingExtensions
|
55
33
|
|
56
34
|
end # namespace FileBlobs
|
@@ -51,6 +51,7 @@ module ActiveRecordExtensions::ClassMethods
|
|
51
51
|
# The FileBlob storing the file's content.
|
52
52
|
belongs_to :#{attribute_name}_blob,
|
53
53
|
{ class_name: #{blob_model.inspect} }, -> { select :id }
|
54
|
+
validates_associated :file_blob
|
54
55
|
|
55
56
|
class #{attribute_name.to_s.classify}Proxy < FileBlobs::FileBlobProxy
|
56
57
|
# Creates a proxy for the given model.
|
@@ -4,13 +4,16 @@ module FileBlobs
|
|
4
4
|
|
5
5
|
# Module mixed into ActiveRecord::ConnectionAdapters::TableDefinition.
|
6
6
|
module ActiveRecordTableDefinitionExtensions
|
7
|
-
# Creates the
|
7
|
+
# Creates the columns used to reference a file blob
|
8
8
|
#
|
9
|
-
# @param [Symbol]
|
9
|
+
# @param [Symbol] column_name_base the prefix used to generate column names;
|
10
|
+
# this should match the attribute name given to has_file_blob
|
10
11
|
# @param [Hash<Symbol, Object>] options
|
11
12
|
# @option options [Boolean] null true
|
12
|
-
# @option options [Integer]
|
13
|
-
#
|
13
|
+
# @option options [Integer] mime_type_limit the maximum size of the column
|
14
|
+
# used to store the file name provided by the user's browser
|
15
|
+
# @option options [Integer] file_name_limit the maximum size of the column
|
16
|
+
# used to store the file blob's MIME type
|
14
17
|
def file_blob(column_name_base = :file, options = {}, &block)
|
15
18
|
allow_null = options[:null] || false
|
16
19
|
mime_type_limit = options[:mime_type_limit] || 64
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class ActiveRecordExtensionsTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@blob_owner = blob_owners(:ruby)
|
6
|
+
end
|
7
|
+
|
8
|
+
test 'referenced blob validation' do
|
9
|
+
@blob_owner.file.data = ' ' * 1.megabyte
|
10
|
+
assert !@blob_owner.valid?
|
11
|
+
assert_not_empty @blob_owner.errors[:file_blob]
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file_blobs_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Costan
|
@@ -233,6 +233,7 @@ files:
|
|
233
233
|
- lib/file_blobs_rails/generators/templates/file_blobs.yml.erb
|
234
234
|
- lib/file_blobs_rails/generators/templates/files/invoice.pdf
|
235
235
|
- lib/file_blobs_rails/generators/templates/files/ruby.png
|
236
|
+
- test/active_record_extensions_test.rb
|
236
237
|
- test/blob_model_test.rb
|
237
238
|
- test/blob_owner_test.rb
|
238
239
|
- test/controller_extensions_test.rb
|