Project

mordor

0.0
Repository is archived
No release in over 3 years
Low commit activity in last 3 years
Small gem to add MongoDB Resources, resources have attributes that translate into document fields. When an attribute is declared, finders for the attribute are added to the Resource automatically
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 12.3.3
~> 2.0, < 2.99

Runtime

>= 0
~> 2.3.0
< 2.0.0
 Project Readme

CircleCI

Introduction

Small library to add DataMapper style resources for MongoDB.

class ExampleResource
  include Mordor::Resource

  attribute :first, :index => true
  attribute :second
  attribute :third, :finder_method => :find_by_third_attribute
  attribute :at,    :timestamp => true
end

This adds attr_accessors to the ExampleResource for each attribute, plus adds finder methods of the form find_by_{attribute}. The naming convention can be overridden by using the optional :finder_method option, as can be seen with the third attribute.

When the :index => true option is set, indices are ensured before each query on the collection. Indices are descending by default, but this can be changed by also supplying a :index_type => Mongo::ASCENDING option.

At most one attribute per Resource can have the option :timestamp => true set. This means that the attribute will be saved as one of the two first attributes (the other one being the _id attribute. When no value is given for the timestamped attribute, a timestamp with value 0 will be inserted, which results in a timestamp being assigned to it by the MongoDB. An exception is raised when more than one attribute is given the timestamp option