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

Class Method Summary collapse

Instance Attribute Details

#fromGuacamole::Model (readonly)

The model on the from side of the edge

Returns:



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

#toGuacamole::Model (readonly)

The model on the to side of the edge

Returns:



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

Parameters:

  • collection_name (Symbol)

    The name of the originating collection



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

Parameters:

  • collection_name (Symbol)

    The name of the target collection



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