This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "sequel" | |
require "benchmark" | |
system "createdb testing" | |
DB = Sequel.postgres("testing") | |
at_exit do | |
DB.disconnect | |
system "dropdb testing" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### | |
# 1. Simple assertion of required arguments | |
#### | |
# - You can forget #fetch | |
# - You get a better error, and always on the line where method is defined | |
def search(options = {}) | |
query = options.fetch(:query) | |
end | |
search() # => KeyError: key not found :query |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "sequel" | |
DB = Sequel.postgres("arel") | |
DB.create_table!(:movies) { primary_key :id } | |
class Movie < Sequel::Model | |
end | |
# Asterisk (I agree this one isn't ideal) | |
Movie.select{count{}.*} # SELECT count(*) FROM "movies" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem "shrine", github: "janko-m/shrine" | |
gem "rom-repository" | |
gem "rom-sql" | |
gem "sqlite3" | |
gem "dry-validation" | |
gem "roda" | |
gem "sucker_punch", "~> 2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ImageQuestion < TextQuestion | |
store :data, accessors: [:image] | |
mount_uploader :image, ImageUploader | |
validates :image, download: true, processing: true | |
end | |
class ImageUploader < CarrierWave::Uploader::Base | |
include CarrierWave::MiniMagick |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Shrine | |
module Plugins | |
# The `concatenation` plugin allows you to assign to the attacher a | |
# cached file which is composed of multiple uploaded parts. The plugin | |
# will then call `#concat` on the storage, which is expected to | |
# concatenate the given parts into a single file. The assigned | |
# attachment will then be a complete cached file. | |
# | |
# plugin :concatenation | |
# |