solid_storage 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8f89a01c7211be77a1c7dcb74fe3480c419161a94da0361cbfbd41744e5cdfd
4
- data.tar.gz: 479ad5ec90754640e64e0f42d75ca8368bb2b6f5c84af394354a1fef7ce8a655
3
+ metadata.gz: 6f29e810e3124c7c0a9ddded239f3c6bceceb2d17250b88be373d1e4d65f3651
4
+ data.tar.gz: d3c128af2302982769861e8209e39971847e80a59c1a0fa9424ff54335c7bada
5
5
  SHA512:
6
- metadata.gz: adc433251f4bdf44454cdc0b541977f909786969beef04c056d96ec6da171852c1c2f695b68a56750f5416273ff83161619c73742aebfa44859769c639875cf0
7
- data.tar.gz: 00cab3fcf0359e82363a7f6251f116bd98c4b3699f8ba183982c8739333a1c1ca73cd392dffa8fea5aa361a82dc9d73fe93ae498ea2ac4f71bdd8e9c469f82f6
6
+ metadata.gz: d3b8b123763db97b19569e26e5e1d28762996e401376d8d04e2fa1f85792c691cc5253a9b68ef3a8ca685432ae0418b80d7f3c69771315c00ce12c85f33cdc63
7
+ data.tar.gz: a444670a5d38d8c62ae2cd000a290ddebd515341f95aceff6039b030ecf896161d211572e0122d66cbd183944289124c46b720b909ac618e75ed921a974ff533
data/README.md CHANGED
@@ -1,7 +1,19 @@
1
1
  # Solid Storage
2
2
 
3
- Active Storage service adapter that stores blobs in the database and serves
4
- them using X-Sendfile.
3
+ Solid Storage is an Active Storage service adapter that stores blobs in the
4
+ database and serves them using X-Sendfile and adheres to the Active Storage
5
+ service contract.
6
+
7
+ ## Why?
8
+
9
+ S3, Azure, R2, GCS all cost money. When starting out and trying to keep costs
10
+ low, storing files in the database is just fine. So why not just use the disk
11
+ adapter? The disk adapter only works if you are on a single server, and if you
12
+ are on a single server, the disk adapter can be cumbersome to backup. With
13
+ data in the database, it is easy to backup by incorporating into your current
14
+ database backup process. Having your files easily backup-able will also make
15
+ your app more portable. Solid Storage also uses X-Sendfile just like the disk
16
+ adapter so you get all the upside of the disk adapter.
5
17
 
6
18
  ## Installation
7
19
 
@@ -10,5 +22,51 @@ them using X-Sendfile.
10
22
 
11
23
  This will configure Solid Storage as an Active Storage adapter by overwritting `config/storage.yml`, create `db/storage_schema.rb`, and set the production adapter to `:solid_storage`.
12
24
 
25
+ You will then have to add the configuration for the storage database in `config/database.yml`. If you're using SQLite, it'll look like this:
26
+
27
+ ```yaml
28
+ production:
29
+ primary:
30
+ <<: *default
31
+ database: storage/production.sqlite3
32
+ storage:
33
+ <<: *default
34
+ database: storage/production_strorage.sqlite3
35
+ migrations_paths: db/storage_migrate
36
+ ```
37
+
38
+ ...or if you're using MySQL/PostgreSQL/Trilogy:
39
+
40
+ ```yaml
41
+ production:
42
+ primary: &primary_production
43
+ <<: *default
44
+ database: app_production
45
+ username: app
46
+ password: <%= ENV["APP_DATABASE_PASSWORD"] %>
47
+ cable:
48
+ <<: *primary_production
49
+ database: app_production_storage
50
+ migrations_paths: db/storage_migrate
51
+ ```
52
+
53
+ Then run `db:prepare` in production to ensure the database is created and the schema is loaded.
54
+
55
+ It's also recommended to move Active Storage models into the `storage` database
56
+ as well by adding an initializer:
57
+ ```ruby
58
+ ActiveSupport.on_load(:active_storage_record) do
59
+ connects_to(database: { writing: :storage })
60
+ end
61
+ ```
62
+
63
+ ## Configuration
64
+
65
+ Options are set with `config.solid_storage`.
66
+
67
+ The options are:
68
+
69
+ - `connects_to` - set the Active Record database configuration for the Solid Storage models. All options available in Active Record can be used here.
70
+
13
71
  ## License
14
72
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -5,7 +5,9 @@ class SolidStorage::FilesController < ActiveStorage::DiskController
5
5
 
6
6
  def show
7
7
  if key = decode_verified_key
8
- @file = named_disk_service(key[:service_name]).find(key[:key])
8
+ service = named_disk_service(key[:service_name])
9
+ @file = service.find(key[:key])
10
+ response.headers["Cache-Control"] = service.cache_control if service.cache_control
9
11
  serve_file @file.tempfile, content_type: key[:content_type],
10
12
  disposition: key[:disposition]
11
13
  else
@@ -2,10 +2,13 @@ require "active_storage/service"
2
2
 
3
3
  module ActiveStorage
4
4
  class Service::SolidStorageService < ::ActiveStorage::Service
5
- def initialize(public: false, **options)
5
+ def initialize(public: false, cache_control: nil, **options)
6
6
  @public = public
7
+ @cache_control = cache_control
7
8
  end
8
9
 
10
+ attr_reader :cache_control
11
+
9
12
  def find(key)
10
13
  SolidStorage::File.find_by!(key:)
11
14
  end
@@ -1,5 +1,13 @@
1
1
  module SolidStorage
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace SolidStorage
4
+
5
+ config.solid_storage = ActiveSupport::OrderedOptions.new
6
+
7
+ initializer "solid_storage.config" do
8
+ config.solid_storage.each do |name, value|
9
+ SolidStorage.public_send(:"#{name}=", value)
10
+ end
11
+ end
4
12
  end
5
13
  end
@@ -1,3 +1,3 @@
1
1
  module SolidStorage
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solid_storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Pezza
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-10-18 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activerecord
@@ -82,7 +81,6 @@ metadata:
82
81
  homepage_uri: http://github.com/npezza93/solid_storage
83
82
  source_code_uri: http://github.com/npezza93/solid_storage
84
83
  rubygems_mfa_required: 'true'
85
- post_install_message:
86
84
  rdoc_options: []
87
85
  require_paths:
88
86
  - lib
@@ -97,8 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
95
  - !ruby/object:Gem::Version
98
96
  version: '0'
99
97
  requirements: []
100
- rubygems_version: 3.5.18
101
- signing_key:
98
+ rubygems_version: 3.7.1
102
99
  specification_version: 4
103
100
  summary: Database-backed Active Storage adapter.
104
101
  test_files: []