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::ImmutableSetOf, Contracts::ImmutableSortedSetOf, Contracts::OldResourceList, Contracts::PATH_MATCHER, Contracts::ResourceList, Contracts::VectorOf

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



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

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

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes



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

def attributes
  @attributes
end

#keyObject (readonly)

Returns the value of attribute key



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

def key
  @key
end

Instance Method Details

#==(other) ⇒ Object



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

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

#matches_resource?(_resource) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches_resource?(_resource)
  false
end

#merge!(other) ⇒ Object



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

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

#serialize(attributes = {}) ⇒ Object



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

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

#to_sObject



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

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

#type_idObject



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

def type_id
  self.class.const_get :TYPE_ID
end

#valid?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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

def valid?
  raise NotImplementedError
end