Module: Guacamole::Edge
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/guacamole/edge.rb
Overview
An Edge representing a relation between two models within a Graph
A Guacamole::Edge is specialized model with two predefined attributes (from
and to
)
and a class level DSL to define the relation between models inside a Graph. Like normal
models, edge models don't know the database. But unlike the collection classes you define
yourself for your models Guacamole will create a default collection class to be used with
your edge models.
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#from ⇒ Guacamole::Model
readonly
The model on the from side of the edge.
-
#to ⇒ Guacamole::Model
readonly
The model on the to side of the edge.
Class Method Summary collapse
-
.from(collection_name) ⇒ Object
Define the collection from which all these edges will originate.
-
.to(collection_name) ⇒ Object
Define the collection to which all these edges will direct.
Instance Attribute Details
#from ⇒ Guacamole::Model (readonly)
The model on the from side of the edge
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/guacamole/edge.rb', line 38 module Edge extend ActiveSupport::Concern included do include Guacamole::Model attribute :from, Object attribute :to, Object end module ClassMethods def from(collection_name = nil) if collection_name.nil? @from else @from = collection_name end end def to(collection_name = nil) if collection_name.nil? @to else @to = collection_name end end def to_collection [to.to_s.camelcase, 'Collection'].join('').constantize end def from_collection [from.to_s.camelcase, 'Collection'].join('').constantize end end end |
#to ⇒ Guacamole::Model (readonly)
The model on the to side of the edge
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/guacamole/edge.rb', line 38 module Edge extend ActiveSupport::Concern included do include Guacamole::Model attribute :from, Object attribute :to, Object end module ClassMethods def from(collection_name = nil) if collection_name.nil? @from else @from = collection_name end end def to(collection_name = nil) if collection_name.nil? @to else @to = collection_name end end def to_collection [to.to_s.camelcase, 'Collection'].join('').constantize end def from_collection [from.to_s.camelcase, 'Collection'].join('').constantize end end end |
Class Method Details
.from(collection_name) ⇒ Object
Define the collection from which all these edges will originate
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/guacamole/edge.rb', line 38 module Edge extend ActiveSupport::Concern included do include Guacamole::Model attribute :from, Object attribute :to, Object end module ClassMethods def from(collection_name = nil) if collection_name.nil? @from else @from = collection_name end end def to(collection_name = nil) if collection_name.nil? @to else @to = collection_name end end def to_collection [to.to_s.camelcase, 'Collection'].join('').constantize end def from_collection [from.to_s.camelcase, 'Collection'].join('').constantize end end end |
.to(collection_name) ⇒ Object
Define the collection to which all these edges will direct
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/guacamole/edge.rb', line 38 module Edge extend ActiveSupport::Concern included do include Guacamole::Model attribute :from, Object attribute :to, Object end module ClassMethods def from(collection_name = nil) if collection_name.nil? @from else @from = collection_name end end def to(collection_name = nil) if collection_name.nil? @to else @to = collection_name end end def to_collection [to.to_s.camelcase, 'Collection'].join('').constantize end def from_collection [from.to_s.camelcase, 'Collection'].join('').constantize end end end |