Class: Middleman::Dependencies::Vertex

Inherits:
Object
  • Object
show all
Includes:
Contracts
Defined in:
middleman-core/lib/middleman-core/dependencies/vertices/vertex.rb

Constant Summary collapse

VERTEX_KEY =
Symbol
VERTEX_ATTRS =
HashOf[Symbol, String]
SERIALIZED_VERTEX_ATTRS =
HashOf[String, String]
SERIALIZED_VERTEX =
{
  'key' => Any, # Weird type inheritance bug
  'type' => String,
  'attrs' => SERIALIZED_VERTEX_ATTRS
}.freeze

Constants included from Contracts

Contracts::PATH_MATCHER

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Contracts

#Contract

Constructor Details

#initialize(key, attributes) ⇒ Vertex

Returns a new instance of Vertex.


27
28
29
30
# File 'middleman-core/lib/middleman-core/dependencies/vertices/vertex.rb', line 27

def initialize(key, attributes)
  @key = key
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.


24
25
26
# File 'middleman-core/lib/middleman-core/dependencies/vertices/vertex.rb', line 24

def attributes
  @attributes
end

#keyObject (readonly)

Returns the value of attribute key.


21
22
23
# File 'middleman-core/lib/middleman-core/dependencies/vertices/vertex.rb', line 21

def key
  @key
end

Instance Method Details

#==(other) ⇒ Object


33
34
35
# File 'middleman-core/lib/middleman-core/dependencies/vertices/vertex.rb', line 33

def ==(other)
  key == other.key
end

#matches_resource?(_resource) ⇒ Boolean

Returns:

  • (Boolean)

48
49
50
# File 'middleman-core/lib/middleman-core/dependencies/vertices/vertex.rb', line 48

def matches_resource?(_resource)
  false
end

#merge!(other) ⇒ Object


43
44
45
# File 'middleman-core/lib/middleman-core/dependencies/vertices/vertex.rb', line 43

def merge!(other)
  @attributes.merge!(other.attributes)
end

#serialize(attributes = {}) ⇒ Object


53
54
55
56
57
58
59
# File 'middleman-core/lib/middleman-core/dependencies/vertices/vertex.rb', line 53

def serialize(attributes = {})
  {
    'key' => @key.to_s,
    'type' => type_id.to_s,
    'attrs' => @attributes.merge(attributes).stringify_keys
  }
end

#to_sObject


62
63
64
# File 'middleman-core/lib/middleman-core/dependencies/vertices/vertex.rb', line 62

def to_s
  "<Vertex type=#{type_id} key=#{key}>"
end

#type_idObject


67
68
69
# File 'middleman-core/lib/middleman-core/dependencies/vertices/vertex.rb', line 67

def type_id
  self.class.const_get :TYPE_ID
end

#valid?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)

38
39
40
# File 'middleman-core/lib/middleman-core/dependencies/vertices/vertex.rb', line 38

def valid?
  raise NotImplementedError
end