Sha256: 62cbe72a23a3f72fd0cbef5c50c7ea9af84bb11c703e61376b6a4f06893e97ee

Contents?: true

Size: 973 Bytes

Versions: 19

Compression:

Stored size: 973 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]
          fail ModelNotFound, "Couldn't find #{self} matching #{args}." unless m
          m
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
sequel-rails-0.9.17 lib/sequel_rails/sequel/plugins/rails_extensions.rb
sequel-rails-0.9.16 lib/sequel_rails/sequel/plugins/rails_extensions.rb
sequel-rails-0.9.15 lib/sequel_rails/sequel/plugins/rails_extensions.rb
sequel-rails-0.9.14 lib/sequel_rails/sequel/plugins/rails_extensions.rb
sequel-rails-0.9.13 lib/sequel_rails/sequel/plugins/rails_extensions.rb
sequel-rails-0.9.12 lib/sequel_rails/sequel/plugins/rails_extensions.rb
sequel-rails-0.9.11 lib/sequel_rails/sequel/plugins/rails_extensions.rb
sequel-rails-0.9.10 lib/sequel_rails/sequel/plugins/rails_extensions.rb
sequel-rails-0.9.9 lib/sequel_rails/sequel/plugins/rails_extensions.rb
sequel-rails-0.9.8 lib/sequel_rails/sequel/plugins/rails_extensions.rb
sequel-rails-0.9.7 lib/sequel_rails/sequel/plugins/rails_extensions.rb
sequel-rails-0.9.6 lib/sequel_rails/sequel/plugins/rails_extensions.rb
sequel-rails-0.9.5 lib/sequel_rails/sequel/plugins/rails_extensions.rb
sequel-rails-0.9.4 lib/sequel_rails/sequel/plugins/rails_extensions.rb
sequel-rails-0.9.3 lib/sequel_rails/sequel/plugins/rails_extensions.rb
sequel-rails-0.9.2 lib/sequel_rails/sequel/plugins/rails_extensions.rb
sequel-rails-0.9.1 lib/sequel_rails/sequel/plugins/rails_extensions.rb
sequel-rails-0.9.0 lib/sequel_rails/sequel/plugins/rails_extensions.rb
sequel-rails-0.8.0 lib/sequel_rails/sequel/plugins/rails_extensions.rb