Module: DataMapper::Has::Slug
- Included in:
- Resource::ClassMethods
- Defined in:
- lib/dm-slug/has/slug.rb,
lib/dm-slug/has/version.rb
Constant Summary collapse
- VERSION =
"0.9.10"
Instance Method Summary collapse
-
#has_slug(options = {}) ⇒ Object
Methods that should be included in DataMapper::Model.
Instance Method Details
#has_slug(options = {}) ⇒ Object
Methods that should be included in DataMapper::Model. Normally this should just be your generator, so that the namespace does not get cluttered. ClassMethods and InstanceMethods gets added in the specific resources when you fire is :example
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dm-slug/has/slug.rb', line 12 def has_slug( = {}) = { :on => :name, :called => :slug, :length => 50 }.merge() if properties.has_property? [:on] p = properties[[:on]] p_opts = {:length => p.length, :lazy => p.lazy?, :nullable => p.nullable?, :unique_index => (p.unique or p.unique_index)} else p_opts = {:length => [:length]} end property [:called], DataMapper::Types::Slug, p_opts before :valid? do attribute_set([:called], self.send([:on])) end end |