Class: Nanoc::Int::ItemRep Private
- Inherits:
-
Object
- Object
- Nanoc::Int::ItemRep
- Includes:
- ContractsSupport
- Defined in:
- lib/nanoc/base/entities/item_rep.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #compiled ⇒ Boolean (also: #compiled?) private
- #item ⇒ Nanoc::Int::Item readonly private
- #modified ⇒ Boolean (also: #modified?) private
- #name ⇒ Symbol readonly private
- #paths ⇒ Hash<Symbol,String> private
- #raw_paths ⇒ Hash<Symbol,String> private
- #snapshot_contents ⇒ Hash<Symbol,Nanoc::Int::Content> private
-
#snapshot_defs ⇒ Enumerable<Nanoc::Int:SnapshotDef]
private
Enumerable<Nanoc::Int:SnapshotDef].
Instance Method Summary collapse
- #binary? ⇒ Boolean private
-
#compiled_content(snapshot: nil) ⇒ String
private
Returns the compiled content from a given snapshot.
-
#forget_progress ⇒ void
private
Resets the compilation progress for this item representation.
-
#initialize(item, name) ⇒ ItemRep
constructor
private
A new instance of ItemRep.
- #inspect ⇒ Object private
-
#path(snapshot: :last) ⇒ String
private
Returns the item rep’s path, as used when being linked to.
-
#raw_path(snapshot: :last) ⇒ String
private
Returns the item rep’s raw path.
-
#reference ⇒ Object
private
Returns an object that can be used for uniquely identifying objects.
-
#snapshot?(snapshot_name) ⇒ Boolean
(also: #has_snapshot?)
private
Checks whether content exists at a given snapshot.
Methods included from ContractsSupport
Constructor Details
#initialize(item, name) ⇒ ItemRep
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ItemRep.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/nanoc/base/entities/item_rep.rb', line 36 def initialize(item, name) # Set primary attributes @item = item @name = name # Set default attributes @raw_paths = {} @paths = {} @snapshot_defs = [] initialize_content # Reset flags @compiled = false end |
Instance Attribute Details
#compiled ⇒ Boolean Also known as: compiled?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
10 11 12 |
# File 'lib/nanoc/base/entities/item_rep.rb', line 10 def compiled @compiled end |
#item ⇒ Nanoc::Int::Item (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 |
# File 'lib/nanoc/base/entities/item_rep.rb', line 20 def item @item end |
#modified ⇒ Boolean Also known as: modified?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
29 30 31 |
# File 'lib/nanoc/base/entities/item_rep.rb', line 29 def modified @modified end |
#name ⇒ Symbol (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
23 24 25 |
# File 'lib/nanoc/base/entities/item_rep.rb', line 23 def name @name end |
#paths ⇒ Hash<Symbol,String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
17 18 19 |
# File 'lib/nanoc/base/entities/item_rep.rb', line 17 def paths @paths end |
#raw_paths ⇒ Hash<Symbol,String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 |
# File 'lib/nanoc/base/entities/item_rep.rb', line 14 def raw_paths @raw_paths end |
#snapshot_contents ⇒ Hash<Symbol,Nanoc::Int::Content>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
7 8 9 |
# File 'lib/nanoc/base/entities/item_rep.rb', line 7 def snapshot_contents @snapshot_contents end |
#snapshot_defs ⇒ Enumerable<Nanoc::Int:SnapshotDef]
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Enumerable<Nanoc::Int:SnapshotDef].
26 27 28 |
# File 'lib/nanoc/base/entities/item_rep.rb', line 26 def snapshot_defs @snapshot_defs end |
Instance Method Details
#binary? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
52 53 54 |
# File 'lib/nanoc/base/entities/item_rep.rb', line 52 def binary? @snapshot_contents[:last].binary? end |
#compiled_content(snapshot: nil) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the compiled content from a given snapshot.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/nanoc/base/entities/item_rep.rb', line 66 def compiled_content(snapshot: nil) # Make sure we're not binary if binary? raise Nanoc::Int::Errors::CannotGetCompiledContentOfBinaryItem.new(self) end # Get name of last pre-layout snapshot snapshot_name = snapshot || (@snapshot_contents[:pre] ? :pre : :last) is_moving = [:pre, :post, :last].include?(snapshot_name) # Check existance of snapshot snapshot_def = snapshot_defs.reverse.find { |sd| sd.name == snapshot_name } if !is_moving && (snapshot_def.nil? || !snapshot_def.final?) raise Nanoc::Int::Errors::NoSuchSnapshot.new(self, snapshot_name) end # Verify snapshot is usable is_still_moving = case snapshot_name when :post, :last true when :pre snapshot_def.nil? || !snapshot_def.final? end is_usable_snapshot = @snapshot_contents[snapshot_name] && (compiled? || !is_still_moving) unless is_usable_snapshot raise Nanoc::Int::Errors::UnmetDependency.new(self) end @snapshot_contents[snapshot_name].string end |
#forget_progress ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Resets the compilation progress for this item representation. This is necessary when an unmet dependency is detected during compilation.
143 144 145 146 |
# File 'lib/nanoc/base/entities/item_rep.rb', line 143 def forget_progress initialize_content nil end |
#inspect ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
157 158 159 |
# File 'lib/nanoc/base/entities/item_rep.rb', line 157 def inspect "<#{self.class} name=\"#{name}\" binary=#{binary?} raw_path=\"#{raw_path}\" item.identifier=\"#{item.identifier}\">" end |
#path(snapshot: :last) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the item rep’s path, as used when being linked to. It starts with a slash and it is relative to the output directory. It does not include the path to the output directory. It will not include the filename if the filename is an index filename.
132 133 134 |
# File 'lib/nanoc/base/entities/item_rep.rb', line 132 def path(snapshot: :last) @paths[snapshot] end |
#raw_path(snapshot: :last) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the item rep’s raw path. It includes the path to the output directory and the full filename.
118 119 120 |
# File 'lib/nanoc/base/entities/item_rep.rb', line 118 def raw_path(snapshot: :last) @raw_paths[snapshot] end |
#reference ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns an object that can be used for uniquely identifying objects.
153 154 155 |
# File 'lib/nanoc/base/entities/item_rep.rb', line 153 def reference [:item_rep, item.identifier, name] end |
#snapshot?(snapshot_name) ⇒ Boolean Also known as: has_snapshot?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks whether content exists at a given snapshot.
105 106 107 |
# File 'lib/nanoc/base/entities/item_rep.rb', line 105 def snapshot?(snapshot_name) !@snapshot_contents[snapshot_name].nil? end |