refile-postgres 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb79dfe21ef11e8e168357f538f2a4c51a83095b
4
- data.tar.gz: 66d562ee82b791458b122d3eb950d660a28144c8
3
+ metadata.gz: 712efea6017857a480caaf1672ae828389ef21fc
4
+ data.tar.gz: d8e138e6289d25977aa4643bf8ac8cbf216317b0
5
5
  SHA512:
6
- metadata.gz: 450be3febecd24b2856bb9429166ba94f66aabff229b0056aeae0d5d5103a604295d23d95ced7ce381518fd31a20615d78551f4f30797866bbf7c0a9bb0ca41b
7
- data.tar.gz: b5d83e96ccf67e3e046430215db09a513265ef5ae6c73227cb283b5a2c4d51a8015bf558b0859336592610f83513e07d90b6f886c8085f039bd628dbdf15261d
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
- TODO: Write usage instructions here
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
- connection.exec %{
19
- SELECT count(*) from pg_catalog.pg_tables
20
- WHERE tablename = '#{@registry_table}';
21
- } do |result|
22
- unless result[0]["count"].to_i > 0
23
- raise RegistryTableDoesNotExistError.new(%{Please create a table "#{@registry_table}" where backend could store list of attachments})
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
- Reader.new(connection, id)
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}
@@ -1,5 +1,5 @@
1
1
  module Refile
2
2
  module Postgres
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refile-postgres
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krists Ozols