Class: Middleman::Dependencies::FileVertex

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

Constant Summary collapse

TYPE_ID =
:file

Constants included from Contracts

Contracts::ImmutableSetOf, Contracts::ImmutableSortedSetOf, Contracts::OldResourceList, Contracts::PATH_MATCHER, Contracts::ResourceList, Contracts::VectorOf

Constants inherited from Vertex

Vertex::SERIALIZED_VERTEX, Vertex::SERIALIZED_VERTEX_ATTRS, Vertex::VERTEX_ATTRS, Vertex::VERTEX_KEY

Instance Attribute Summary

Attributes inherited from Vertex

#attributes, #key

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Contracts

#Contract

Methods inherited from Vertex

#==, #merge!, #to_s, #type_id

Constructor Details

#initialize(root, key, attributes = {}) ⇒ FileVertex

Returns a new instance of FileVertex


28
29
30
31
32
# File 'middleman-core/lib/middleman-core/dependencies/vertices/file_vertex.rb', line 28

def initialize(root, key, attributes = {})
  @root = Pathname(root)
  @full_path = full_path(@root, key.to_s)
  super(relative_path(@root, key.to_s).to_sym, attributes)
end

Class Method Details

.deserialize(app, key, attributes) ⇒ Object


13
14
15
# File 'middleman-core/lib/middleman-core/dependencies/vertices/file_vertex.rb', line 13

def self.deserialize(app, key, attributes)
  FileVertex.new(app.root_path, key, attributes.symbolize_keys)
end

.from_resource(resource) ⇒ Object


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

def self.from_resource(resource)
  from_source_file(resource.app, resource.file_descriptor)
end

.from_source_file(app, source_file) ⇒ Object


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

def self.from_source_file(app, source_file)
  FileVertex.new(app.root_path, source_file[:full_path].to_s.to_sym)
end

Instance Method Details

#matches_resource?(resource) ⇒ Boolean

Returns:

  • (Boolean)

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

def matches_resource?(resource)
  resource.file_descriptor[:full_path].to_s == @full_path
end

#serializeObject


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

def serialize
  super({
    hash: valid? && !previous_hash.nil? ? previous_hash : hash_file
  })
end

#valid?Boolean

Returns:

  • (Boolean)

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

def valid?
  @is_valid = (previous_hash.nil? || hash_file == previous_hash) if @is_valid.nil?
  @is_valid
end