Class: Middleman::Dependencies::FileVertex
- Inherits:
-
Vertex
- Object
- Vertex
- Middleman::Dependencies::FileVertex
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::PATH_MATCHER
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.
30
31
32
33
34
|
# File 'middleman-core/lib/middleman-core/dependencies/vertices/file_vertex.rb', line 30
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
15
16
17
|
# File 'middleman-core/lib/middleman-core/dependencies/vertices/file_vertex.rb', line 15
def self.deserialize(app, key, attributes)
FileVertex.new(app.root_path, key, attributes.symbolize_keys)
end
|
.from_resource(resource) ⇒ Object
20
21
22
|
# File 'middleman-core/lib/middleman-core/dependencies/vertices/file_vertex.rb', line 20
def self.from_resource(resource)
from_source_file(resource.app, resource.file_descriptor)
end
|
.from_source_file(app, source_file) ⇒ Object
25
26
27
|
# File 'middleman-core/lib/middleman-core/dependencies/vertices/file_vertex.rb', line 25
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
43
44
45
|
# File 'middleman-core/lib/middleman-core/dependencies/vertices/file_vertex.rb', line 43
def matches_resource?(resource)
resource.file_descriptor[:full_path].to_s == @full_path
end
|
#serialize ⇒ Object
48
49
50
51
52
|
# File 'middleman-core/lib/middleman-core/dependencies/vertices/file_vertex.rb', line 48
def serialize
super({
hash: valid? && !previous_hash.nil? ? previous_hash : hash_file
})
end
|
#valid? ⇒ Boolean
37
38
39
40
|
# File 'middleman-core/lib/middleman-core/dependencies/vertices/file_vertex.rb', line 37
def valid?
@is_valid = ((File.exist? @full_path) && (previous_hash.nil? || hash_file == previous_hash)) if @is_valid.nil?
@is_valid
end
|