Class: Mongoid::SleepingKingStudios::Sluggable::Metadata

Inherits:
Concern::Metadata show all
Defined in:
lib/mongoid/sleeping_king_studios/sluggable/metadata.rb

Overview

Stores information about a Sluggable concern.

Since:

  • 0.1.0

Instance Attribute Summary

Attributes inherited from Concern::Metadata

#name, #properties

Instance Method Summary collapse

Methods inherited from Concern::Metadata

#characterize, #initialize, #relation_key, #relation_key?

Constructor Details

This class inherits a constructor from Mongoid::SleepingKingStudios::Concern::Metadata

Instance Method Details

#attributeSymbol

The base attribute used to determine the slug value.

Returns:

  • (Symbol)

    The attribute name.

Since:

  • 0.1.0



12
13
14
# File 'lib/mongoid/sleeping_king_studios/sluggable/metadata.rb', line 12

def attribute
  self[:attribute].to_s.intern
end

#attribute?Boolean

Returns True if the attribute is defined; otherwise false.

Returns:

  • (Boolean)

    True if the attribute is defined; otherwise false.

Since:

  • 0.1.0



17
18
19
# File 'lib/mongoid/sleeping_king_studios/sluggable/metadata.rb', line 17

def attribute?
  !!self[:attribute]
end

#lockable?Boolean

If true, the slug can be “locked” by setting the slug value directly or by setting the value of the :slug_lock field to true. A locked slug is not overwritten when the base field is updated.

Returns:

  • (Boolean)

    True if the slug is lockable; otherwise false.

Since:

  • 0.1.0



26
27
28
# File 'lib/mongoid/sleeping_king_studios/sluggable/metadata.rb', line 26

def lockable?
  !!self[:lockable]
end

#value_to_slug(value) ⇒ String

Converts the given value to a valid slug string. Refactoring this into the metadata will permit customization of the value -> slug mapping in the future.

Parameters:

  • value (Object)

    The value to convert into a slug.

Returns:

  • (String)

    The converted value.

Since:

  • 0.1.0



37
38
39
# File 'lib/mongoid/sleeping_king_studios/sluggable/metadata.rb', line 37

def value_to_slug value
  value.to_s.parameterize
end