├── .gitignore ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── lib ├── sequel-devise.rb ├── sequel-devise │ └── version.rb └── sequel │ └── plugins │ └── devise.rb └── sequel-devise.gemspec /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | pkg 13 | rdoc 14 | spec/reports 15 | test/tmp 16 | test/version_tmp 17 | tmp 18 | 19 | # vim swap files: 20 | *.swp 21 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in sequel-devise.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Rodrigo Rosenfeld Rosas 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Project has moved 2 | 3 | This project is no longer maintained in this repository. 4 | Please head over to [ontohub/sequel-devise](https://github.com/ontohub/sequel-devise) for the current version. 5 | 6 | # Sequel::Devise 7 | 8 | Allows the usage of a Sequel::Model class as a Devise mapping. 9 | 10 | ## Installation 11 | 12 | Add this line to your application's Gemfile: 13 | 14 | gem 'sequel-devise' 15 | 16 | And then execute: 17 | 18 | $ bundle 19 | 20 | Or install it yourself as: 21 | 22 | $ gem install sequel-devise 23 | 24 | ## Usage 25 | 26 | class User < Sequel::Model 27 | plugin :devise 28 | devise :database_authenticatable 29 | end 30 | 31 | If you're interested in more instructions on using Sequel with Rails, 32 | I've written [some instructions](http://rosenfeld.herokuapp.com/en/articles/2012-04-18-getting-started-with-sequel-in-rails) in my web site. 33 | 34 | ## Important Note 35 | 36 | Unfortunately Devise does not rely on the `orm_adapter` specs as 37 | [it was supposed to](https://github.com/plataformatec/devise/blob/master/devise.gemspec#L22). 38 | 39 | It will assume the model support other methods besides those defined by `orm_adapter` and that they 40 | behave like the equivalent in ActiveRecord supporting the same arguments. 41 | 42 | In some cases, it will call some method which is not defined by `Sequel::Model`, so we implement 43 | them in this gem, but there are some cases which are trickier. For example, Devise will call the 44 | `save` method in the model and expect it to return false if the validation fails. This is not the 45 | default behavior of Sequel::Model, so you'll have to change this behavior for your User classes 46 | that are intended to be used by Devise. There are a few solutions depending on your use case: 47 | 48 | Please make sure you take a look at the implementation to understand which methods are added 49 | in order to support Devise. Particularly, for security reasons Devise will override inspect 50 | so that it doesn't display passwords hashes for example among other keys. If you want the 51 | original inspect, call `user.inspect(false)`. 52 | 53 | ### You expect your Sequel Models to not raise on save failure by default 54 | 55 | Just disable the raise behavior by default: 56 | 57 | Sequel::Model.raise_on_save_failure = false 58 | 59 | ### You are okay with changing the raise behavior only for your user classes 60 | 61 | class User < Sequel::Model 62 | self.raise_on_save_failure = false 63 | plugin :devise 64 | devise :database_authenticatable 65 | end 66 | 67 | ### You don't want to touch your user model just to accomodate Devise 68 | 69 | You are free to simply create another user class that is meant to be used by Devise while the 70 | remaining of your application just use your regular user class: 71 | 72 | class DeviseUser < User 73 | self.raise_on_save_failure = false 74 | plugin :devise 75 | devise :database_authenticatable 76 | end 77 | 78 | ## Contributing 79 | 80 | 1. Fork it 81 | 2. Create your feature branch (`git checkout -b my-new-feature`) 82 | 3. Commit your changes (`git commit -am 'Added some feature'`) 83 | 4. Push to the branch (`git push origin my-new-feature`) 84 | 5. Create new Pull Request 85 | 86 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | require "bundler/gem_tasks" 3 | -------------------------------------------------------------------------------- /lib/sequel-devise.rb: -------------------------------------------------------------------------------- 1 | require "sequel-devise/version" 2 | require 'sequel/plugins/devise' 3 | require 'orm_adapter-sequel' 4 | 5 | module Sequel 6 | module Devise 7 | # Your code goes here... 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/sequel-devise/version.rb: -------------------------------------------------------------------------------- 1 | module Sequel 2 | module Devise 3 | VERSION = "0.0.9" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/sequel/plugins/devise.rb: -------------------------------------------------------------------------------- 1 | module Sequel 2 | module Plugins 3 | module Devise 4 | def self.apply(model, options = {}) 5 | model.extend ::Devise::Models 6 | model.plugin :hook_class_methods # Devise requires a before_validation 7 | model.plugin :dirty # email_changed? 8 | model.plugin :validation_class_methods # for using validatable module 9 | end 10 | 11 | module InstanceMethods 12 | def changed? # For rememberable 13 | !changed_columns.empty? 14 | end 15 | 16 | def encrypted_password_changed? # For recoverable and database_authenticatable 17 | new? || column_changed?(:encrypted_password) 18 | end 19 | 20 | def email_changed? # For validatable 21 | new? || column_changed?(:email) 22 | end 23 | 24 | def email_was # For confirmable 25 | column_changes[:email].first 26 | end 27 | 28 | # for database_authenticatable: 29 | def assign_attributes(hash) 30 | set hash 31 | end 32 | 33 | def update_attributes(hash, *ignored) 34 | begin 35 | update(hash) != false 36 | rescue Sequel::ValidationFailed 37 | return false 38 | end 39 | end 40 | 41 | def update_attribute(key, value) 42 | update_attributes key => value 43 | end 44 | 45 | private 46 | 47 | def devise_safe_values 48 | values.delete_if{|k, v| devise_safe_keys.include?(k) || k =~ /password/i } 49 | end 50 | 51 | def devise_safe_keys 52 | ::Devise::Models::Authenticatable::BLACKLIST_FOR_SERIALIZATION 53 | end 54 | end 55 | 56 | module ClassMethods 57 | 58 | def human_attribute_name(key) 59 | key.to_s 60 | end 61 | 62 | module OverrideFixes 63 | def inspect(safe = true) 64 | return self.class.superclass.instance_method(:inspect).bind(self)[] unless safe 65 | "#<#{self.class} @values=#{devise_safe_values.inspect}>" 66 | end 67 | end 68 | 69 | def devise_modules_hook! 70 | yield 71 | include OverrideFixes 72 | end 73 | 74 | Model::HOOKS.each do |hook| 75 | define_method(hook) do |method = nil, options = {}, &block| 76 | if Symbol === (if_method = options[:if]) 77 | orig_block = block 78 | block = nil 79 | method_without_if = method 80 | method = :"_sequel_hook_with_if_#{method}" 81 | define_method(method) do 82 | return unless send if_method 83 | send method_without_if 84 | instance_eval &orig_block if orig_block 85 | end 86 | private method 87 | end 88 | super method, &block 89 | end 90 | end 91 | end 92 | end 93 | end 94 | end 95 | -------------------------------------------------------------------------------- /sequel-devise.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | require File.expand_path('../lib/sequel-devise/version', __FILE__) 3 | 4 | Gem::Specification.new do |gem| 5 | gem.authors = ["Rodrigo Rosenfeld Rosas"] 6 | gem.email = ["rr.rosas@gmail.com"] 7 | gem.description = %q{Devise support for Sequel models} 8 | gem.summary = %q{Enable Devise support by adding plugin :devise to your Sequel Model} 9 | gem.homepage = "https://github.com/rosenfeld/sequel-devise" 10 | 11 | gem.files = `git ls-files`.split($\) 12 | gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } 13 | gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) 14 | gem.name = "sequel-devise" 15 | gem.require_paths = ["lib"] 16 | gem.version = Sequel::Devise::VERSION 17 | 18 | gem.add_dependency 'devise' 19 | gem.add_dependency 'orm_adapter-sequel' 20 | end 21 | --------------------------------------------------------------------------------