It is very difficult to debug a problem without a simple example.
You can clone this repository here with everything set up, to make this as easy as possible to debug.
But if you wish to set things up manually, please follow the guide lines below.
require "sequel"
require "shrine"
require "shrine/storage/memory"
require "down"
Shrine.storages = {
cache: Shrine::Storage::Memory.new,
store: Shrine::Storage::Memory.new,
}
Shrine.plugin :sequel
class MyUploader < Shrine
# plugins and uploading logic
end
DB = Sequel.sqlite # SQLite memory database
DB.create_table :posts do
primary_key :id
String :image_data
end
class Post < Sequel::Model
include MyUploader::Attachment(:image)
end
post = Post.create(image: Down.download("https://example.com/image-from-internet.jpg"))
# Your code for reproducing
require "active_record"
require "shrine"
require "shrine/storage/memory"
require "down"
Shrine.storages = {
cache: Shrine::Storage::Memory.new,
store: Shrine::Storage::Memory.new,
}
Shrine.plugin :activerecord
class MyUploader < Shrine
# plugins and uploading logic
end
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.connection.create_table(:posts) { |t| t.text :image_data }
class Post < ActiveRecord::Base
include MyUploader::Attachment(:image)
end
post = Post.create(image: Down.download("https://example.com/image-from-internet.jpg"))
# Your code for reproducing
You can either:
-
Create a Gemfile and add the necessary gems.
-
Inline the required gems in the script - if you don't want to create a Gemfile.
# Gemfile
source 'https://rubygems.org' do
gem "activerecord" # replace with gem "sequel" if you're using it
gem 'shrine'
gem "down"
end
-
Run
bundle install
. -
Run the template with:
ruby template_name.rb
.
- Add the following to the above template script (not a Gemfile)
## template_name.rb
## Append the following to the top of the ruby template script
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem "activerecord" # replace with gem "sequel" if you're using it
gem 'shrine'
end
# include the rest of the template script below:
- Run the template with
ruby template_name.rb
.
If you would like to debug or step through Shrine's code using the above template scripts, follow these steps:
-
Download (or clone) Shrine's repository to your local machine
git clone https://github.com/shrinerb/shrine.git
(or you could create a fork of the above repository and clone your fork - this will make it easier for you if you want to make a pull request). -
Checkout the version of shrine you are using by running
git checkout <version_tag>
. -
Modify the Shrine gem line in your
Gemfile
to point to the local copy of Shrine code:
gem "shrine", path: "/path/to/your/local/shrine/gem/code"
-
If needed, add a debugger like
byebug
orpry
to theGemfile
. -
Run
bundle install
. -
Add
require "bundler/setup"
to the top of the template script. -
You can add debugger statement anywhere in your template file or Shrine code.
-
Run
ruby template_name.rb
.