Sha256: ff2c034ebe85d487d336b74514eb8dbf1d4ae33d2b048c26b02e4c79f2bbd6cc
Contents?: true
Size: 975 Bytes
Versions: 13
Compression:
Stored size: 975 Bytes
Contents
require "sequel" module Sequel module Plugins # The RailsExtensions plugin adds a single class method to Sequel::Model in # order to make its use in controllers a little more like ActiveRecord's. # The +find!+ method is added which will raise an exception if no object is # found. By adding the following code to a Railtie: # # config.action_dispatch.rescue_responses.merge!( # 'Sequel::Plugins::RailsExtensions::ModelNotFound' => :not_found # ) # # Usage: # # # Apply plugin to all models: # Sequel::Model.plugin :rails_extensions # # # Apply plugin to a single model: # Album.plugin :rails_extensions module RailsExtensions class ModelNotFound < Sequel::Error end module ClassMethods def find!(args) m = self[args] raise ModelNotFound, "Couldn't find #{self} matching #{args}." unless m m end end end end end
Version data entries
13 entries across 13 versions & 1 rubygems