Module: Dagable::Model
- Defined in:
- lib/dagable/model.rb
Overview
Provides the dagable class method that activates DAG behaviour on an ActiveRecord model. Extend this module in your model, then call dagable to set up edge and ancestry classes, associations, and instance methods.
Usage
class Category < ActiveRecord::Base
extend Dagable::Model
dagable
end
Calling dagable will:
-
Define
Category::Edge(subclass ofDagable::Edge) backed bycategories_edges -
Define
Category::Ancestry(subclass ofDagable::Ancestry) backed bycategories_ancestries -
Include
Dagable::Associationssetting uphas_manyrelationships for edges and ancestry connections -
Include
Dagable::InstanceMethodsprovidingadd_child,add_parent, traversal methods, etc. -
Register an
after_createcallback to insert the self-referential ancestry row (depth 0) for every new record
Class Attribute Summary collapse
-
.mutex ⇒ Object
readonly
Returns the value of attribute mutex.
Instance Method Summary collapse
Class Attribute Details
.mutex ⇒ Object (readonly)
Returns the value of attribute mutex.
39 40 41 |
# File 'lib/dagable/model.rb', line 39 def mutex @mutex end |
Instance Method Details
#dagable ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dagable/model.rb', line 42 def dagable Dagable::Model.mutex.synchronize do edge_klass = const_set("Edge", Class.new(Dagable::Edge)) ancestry_klass = const_set("Ancestry", Class.new(Dagable::Ancestry)) configure_edge_class(edge_klass) configure_ancestry_class(ancestry_klass) include Dagable::Associations.new(edge_klass.name, ancestry_klass.name) include Dagable::InstanceMethods after_create :create_self_ancestry_row end end |