Module: FriendlyId::SequelAdapter::SimpleModel

Defined in:
lib/friendly_id/sequel_adapter/simple_model.rb

Defined Under Namespace

Classes: SingleFinder

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



25
26
27
28
29
# File 'lib/friendly_id/sequel_adapter/simple_model.rb', line 25

def self.included(base)
  def base.primary_key_lookup(pk)
    SingleFinder.new(pk, self).find or super
  end
end

Instance Method Details

#friendly_idObject

Returns the friendly_id.



37
38
39
# File 'lib/friendly_id/sequel_adapter/simple_model.rb', line 37

def friendly_id
  send self.class.friendly_id_config.column
end

#friendly_id_statusObject

Get the FriendlyId::Status after the find has been performed.



32
33
34
# File 'lib/friendly_id/sequel_adapter/simple_model.rb', line 32

def friendly_id_status
  @friendly_id_status ||= Status.new :record => self
end

#to_paramObject

Returns the friendly id, or if none is available, the numeric id.



42
43
44
# File 'lib/friendly_id/sequel_adapter/simple_model.rb', line 42

def to_param
  (friendly_id || id).to_s
end

#validateObject



46
47
48
49
50
51
52
# File 'lib/friendly_id/sequel_adapter/simple_model.rb', line 46

def validate
  return if skip_friendly_id_validations
  column = friendly_id_config.column
  value = send(column)
  return errors.add(column, "can't be blank") if value.blank?
  return errors.add(column, "is reserved") if friendly_id_config.reserved?(value)
end