Sha256: 174c9535681506538e153026e1c849e78824d905529a9ebb274426b215d1ecbb

Contents?: true

Size: 988 Bytes

Versions: 11

Compression:

Stored size: 988 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

11 entries across 11 versions & 2 rubygems

Version Path
vizzuality-sequel-rails-0.3.7 lib/sequel/plugins/rails_extensions.rb
talentbox-sequel-rails-0.3.10 lib/sequel/plugins/rails_extensions.rb
vizzuality-sequel-rails-0.3.6 lib/sequel/plugins/rails_extensions.rb
talentbox-sequel-rails-0.3.9 lib/sequel/plugins/rails_extensions.rb
talentbox-sequel-rails-0.3.8 lib/sequel/plugins/rails_extensions.rb
talentbox-sequel-rails-0.3.7 lib/sequel/plugins/rails_extensions.rb
talentbox-sequel-rails-0.3.6 lib/sequel/plugins/rails_extensions.rb
talentbox-sequel-rails-0.3.5 lib/sequel/plugins/rails_extensions.rb
vizzuality-sequel-rails-0.3.5 lib/sequel/plugins/rails_extensions.rb
vizzuality-sequel-rails-0.3.4 lib/sequel/plugins/rails_extensions.rb
talentbox-sequel-rails-0.3.4 lib/sequel/plugins/rails_extensions.rb