Module: MotionModel
- Defined in:
- lib/motion_model/model/model.rb,
lib/motion_model/version.rb,
lib/motion_model/validatable.rb,
lib/motion_model/model/column.rb,
lib/motion_model/input_helpers.rb,
lib/motion_model/model/persistence.rb,
lib/motion_model/model/finder_query.rb
Overview
MotionModel encapsulates a pattern for synthesizing a model out of thin air. The model will have attributes, types, finders, ordering, … the works.
As an example, consider:
class Task
include MotionModel
columns :task_name => :string,
:details => :string,
:due_date => :date
# any business logic you might add...
end
Now, you can write code like:
Task.create :task_name => 'Walk the dog',
:details => 'Pick up after yourself',
:due_date => '2012-09-17'
Recognized types are:
-
:string
-
:date (must be in YYYY-mm-dd form)
-
:integer
-
:float
Assuming you have a bunch of tasks in your data store, you can do this:
tasks_this_week = Task.where(:due_date).ge(beginning_of_week).and(:due_date).le(end_of_week).order(:due_date)
Partial queries are supported so you can do:
tasks_this_week = Task.where(:due_date).ge(beginning_of_week).and(:due_date).le(end_of_week)
ordered_tasks_this_week = tasks_this_week.order(:due_date)
Defined Under Namespace
Modules: InputHelpers, Model, Validatable Classes: FinderQuery, PersistFileError, RelationIsNilError
Constant Summary collapse
- VERSION =
"0.3.0"