refile-postgres 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -3
- data/lib/refile/postgres/backend.rb +22 -9
- data/lib/refile/postgres/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 712efea6017857a480caaf1672ae828389ef21fc
|
4
|
+
data.tar.gz: d8e138e6289d25977aa4643bf8ac8cbf216317b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f1a41679eee57baa1f760cffcc7b6f873302d5e9122a1bc00709754c63f3b61d0b55bf818552bbd510757184aeaa649e34b9915fca3b06fc8dd028027435227
|
7
|
+
data.tar.gz: 401e7ba330c7821b641012f09fa48c46e288b3d8ef53e3b6b7663224f493655b8582590f1ea7c5c4c8f2b6d31e78f919fb82ab3e2ef880c62838c8ef3ccf00af
|
data/README.md
CHANGED
@@ -30,9 +30,14 @@ Or install it yourself as:
|
|
30
30
|
|
31
31
|
$ gem install refile-postgres
|
32
32
|
|
33
|
-
## Usage
|
34
|
-
|
35
|
-
|
33
|
+
## Usage with Rails
|
34
|
+
|
35
|
+
Generate migration for table were to store list of attachments.
|
36
|
+
$ rails g refile:postgres:migration
|
37
|
+
Run the migrations
|
38
|
+
$ rake db:migrate
|
39
|
+
Generate initializer and set Refile::Postgres as `store` backend.
|
40
|
+
$ rails g refile:postgres:initializer
|
36
41
|
|
37
42
|
## Contributing
|
38
43
|
|
@@ -14,19 +14,27 @@ module Refile
|
|
14
14
|
@connection = connection
|
15
15
|
@namespace = namespace.to_s
|
16
16
|
@registry_table = registry_table
|
17
|
+
@registry_table_validated = false
|
17
18
|
@max_size = max_size
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :connection, :namespace
|
22
|
+
|
23
|
+
def registry_table
|
24
|
+
unless @registry_table_validated
|
25
|
+
connection.exec %{
|
26
|
+
SELECT count(*) from pg_catalog.pg_tables
|
27
|
+
WHERE tablename = '#{@registry_table}';
|
28
|
+
} do |result|
|
29
|
+
unless result[0]["count"].to_i > 0
|
30
|
+
raise RegistryTableDoesNotExistError.new(%{Please create a table "#{@registry_table}" where backend could store list of attachments})
|
31
|
+
end
|
24
32
|
end
|
33
|
+
@registry_table_validated = true
|
25
34
|
end
|
35
|
+
@registry_table
|
26
36
|
end
|
27
37
|
|
28
|
-
attr_reader :connection, :namespace, :registry_table
|
29
|
-
|
30
38
|
def upload(uploadable)
|
31
39
|
Refile.verify_uploadable(uploadable, @max_size)
|
32
40
|
oid = connection.lo_creat
|
@@ -49,7 +57,11 @@ module Refile
|
|
49
57
|
end
|
50
58
|
|
51
59
|
def open(id)
|
52
|
-
|
60
|
+
if exists?(id)
|
61
|
+
Reader.new(connection, id)
|
62
|
+
else
|
63
|
+
raise ArgumentError.new("No such attachment with ID: #{id}")
|
64
|
+
end
|
53
65
|
end
|
54
66
|
|
55
67
|
def read(id)
|
@@ -95,6 +107,7 @@ module Refile
|
|
95
107
|
|
96
108
|
def clear!(confirm = nil)
|
97
109
|
raise ArgumentError, "are you sure? this will remove all files in the backend, call as `clear!(:confirm)` if you're sure you want to do this" unless confirm == :confirm
|
110
|
+
registry_table
|
98
111
|
ensure_in_transaction do
|
99
112
|
connection.exec_params(%{
|
100
113
|
SELECT * FROM #{registry_table}
|