Ants
Collection of concerns and helpers for Rails
+ Mongoid
+ Character
stack.
Id
Orderable
Adds ordering functionality to the model. Default order is assending by _position
field.
Usage:
include Ants:Orderable
NOTE: If this concern is added to model with already existing documents, value for _position
field should be initialized with this command:
ModelClass.all.set(_position: 1000)
OrderableReverse
Meta
Adds set of page meta fields and creates default methods that should be overriden if necessary:
_meta_title
_meta_description
_meta_keywords
_opengraph_image_url
Usage:
include Ants:Meta
Featurable
Hideable
When you need to hide some documents from public or often used as draft analogue:
Usage:
include Ants:Hideable
Scopes:
hidden
not_hidden
Helpers:
hide!
unhide!
hidden?
Slug
Scheduled
Sorted Relations
In Mongoid, the HM & HABTM relations return docs in random order. This workaround provides an ability to retrieve related documents in the same order it was stored.
Usage example:
class Post
include Mongoid::Document
include Ants::SortedRelations
field :title
has_and_belongs_to_many :authors
sorted_relations_for :authors
end
post = Post.new title: 'RESTful actions with Mongosteen'
post.sorted_author_ids = [ Author.create(name: "Oleksandr Kravets").id,
Author.create(name: "Roman Brazhnyk" ).id,
Author.create(name: "Maxim Melnyk" ).id ]
post.sorted_authors.map(&:name)
#=> ['Alexander Kravets', 'Roman Brazhnyk', 'Maxim Melnyk']
Versions
Provides a helper method to get a list of document versions, used by chr
+ mongosteen
:
Usage:
include Ants:Versions
Helpers:
_document_versions