Sequel validations in concerns

304 views Asked by At

I have a Sequel model like this:

class User < Sequel::Model
  include Notificatable

  def validate
    super
    validates_presence [:email]
  end
end

# concerns/notificatable.rb
module Notificatable
    extend ActiveSupport::Concern

    included do
      def validate
        super
        validates_presence [:phone]
      end
    end
end

And here I got a problem: Notificatable validate method overrides the same method in the User model. So there is no :name validations.

How can I fix it? Thanks!

1

There are 1 answers

3
Jeremy Evans On BEST ANSWER

Why use a concern? Simple ruby module inclusion works for what you want:

class User < Sequel::Model
  include Notificatable

  def validate
    super
    validates_presence [:email]
  end
end

# concerns/notificatable.rb
module Notificatable
  def validate
    super
    validates_presence [:phone]
  end
end