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/formotion.rb,
lib/motion_model/model/model_casts.rb,
lib/motion_model/model/persistence.rb,
lib/motion_model/model/transaction.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:

Recognized types are:

  • :string

  • :text

  • :date (must be in YYYY-mm-dd form)

  • :time

  • :integer

  • :float

  • :boolean

  • :array

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: Formotion, InputHelpers, Model, Validatable Classes: FinderQuery, PersistFileError, RelationIsNilError

Constant Summary collapse

VERSION =
"0.3.7"