Module: FriendlyId::DataMapperAdapter::SimpleModel
- Defined in:
- lib/friendly_id/datamapper_adapter/simple_model.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#friendly_id ⇒ Object
Returns the friendly_id.
-
#friendly_id_status ⇒ Object
Get the Status after the find has been performed.
-
#to_param ⇒ Object
Returns the friendly id, or if none is available, the numeric id.
Class Method Details
.included(base) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/friendly_id/datamapper_adapter/simple_model.rb', line 8 def self.included(base) base.class_eval do column = friendly_id_config.column validates_presence_of column, :unless => :skip_friendly_id_validations validates_length_of column, :maximum => friendly_id_config.max_length, :unless => :skip_friendly_id_validations validates_with_method column, :method => :validate_friendly_id, :unless => :skip_friendly_id_validations before :update do @old_friendly_id = original_attributes[properties[friendly_id_config.column]] end after :update, :update_scopes end def base.get(*key) if key.size == 1 return super if key.first.unfriendly_id? column = self.friendly_id_config.column repository = self.repository key = self.key(repository.name).typecast(key) result = self.first(column.to_sym => key) return super unless result result.friendly_id_status.name = name result else super end end end |
Instance Method Details
#friendly_id ⇒ Object
Returns the friendly_id.
44 45 46 |
# File 'lib/friendly_id/datamapper_adapter/simple_model.rb', line 44 def friendly_id send friendly_id_config.column end |
#friendly_id_status ⇒ Object
Get the Status after the find has been performed.
39 40 41 |
# File 'lib/friendly_id/datamapper_adapter/simple_model.rb', line 39 def friendly_id_status @friendly_id_status ||= Status.new(:record => self) end |
#to_param ⇒ Object
Returns the friendly id, or if none is available, the numeric id.
49 50 51 |
# File 'lib/friendly_id/datamapper_adapter/simple_model.rb', line 49 def to_param (friendly_id || id).to_s end |