Class: Nanoc::Core::ItemRep
- Inherits:
-
Object
- Object
- Nanoc::Core::ItemRep
- Includes:
- ContractsSupport
- Defined in:
- lib/nanoc/core/item_rep.rb
Instance Attribute Summary collapse
-
#compiled ⇒ Object
(also: #compiled?)
Returns the value of attribute compiled.
-
#item ⇒ Object
readonly
Returns the value of attribute item.
-
#modified ⇒ Object
(also: #modified?)
Returns the value of attribute modified.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#paths ⇒ Object
Returns the value of attribute paths.
-
#raw_paths ⇒ Object
Returns the value of attribute raw_paths.
-
#snapshot_defs ⇒ Object
Returns the value of attribute snapshot_defs.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(item, name) ⇒ ItemRep
constructor
A new instance of ItemRep.
- #inspect ⇒ Object
-
#path(snapshot: :last) ⇒ Object
Returns the item rep’s path, as used when being linked to.
-
#raw_path(snapshot: :last) ⇒ Object
Returns the item rep’s raw path.
-
#reference ⇒ Object
Returns an object that can be used for uniquely identifying objects.
- #snapshot?(name) ⇒ Boolean
- #to_s ⇒ Object
Methods included from ContractsSupport
enabled?, included, setup_once, warn_about_performance
Constructor Details
#initialize(item, name) ⇒ ItemRep
Returns a new instance of ItemRep.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/nanoc/core/item_rep.rb', line 32 def initialize(item, name) # Set primary attributes @item = item @name = name # Set default attributes @raw_paths = {} @paths = {} @snapshot_defs = [] # Reset flags @compiled = false @modified = false # Precalculate for performance @hash = [self.class, item, name].hash end |
Instance Attribute Details
#compiled ⇒ Object Also known as: compiled?
Returns the value of attribute compiled.
9 10 11 |
# File 'lib/nanoc/core/item_rep.rb', line 9 def compiled @compiled end |
#item ⇒ Object (readonly)
Returns the value of attribute item.
19 20 21 |
# File 'lib/nanoc/core/item_rep.rb', line 19 def item @item end |
#modified ⇒ Object Also known as: modified?
Returns the value of attribute modified.
28 29 30 |
# File 'lib/nanoc/core/item_rep.rb', line 28 def modified @modified end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/nanoc/core/item_rep.rb', line 22 def name @name end |
#paths ⇒ Object
Returns the value of attribute paths.
16 17 18 |
# File 'lib/nanoc/core/item_rep.rb', line 16 def paths @paths end |
#raw_paths ⇒ Object
Returns the value of attribute raw_paths.
13 14 15 |
# File 'lib/nanoc/core/item_rep.rb', line 13 def raw_paths @raw_paths end |
#snapshot_defs ⇒ Object
Returns the value of attribute snapshot_defs.
25 26 27 |
# File 'lib/nanoc/core/item_rep.rb', line 25 def snapshot_defs @snapshot_defs end |
Instance Method Details
#==(other) ⇒ Object
87 88 89 |
# File 'lib/nanoc/core/item_rep.rb', line 87 def ==(other) eql?(other) end |
#eql?(other) ⇒ Boolean
92 93 94 |
# File 'lib/nanoc/core/item_rep.rb', line 92 def eql?(other) other.is_a?(self.class) && item == other.item && name == other.name end |
#hash ⇒ Object
82 83 84 |
# File 'lib/nanoc/core/item_rep.rb', line 82 def hash @hash end |
#inspect ⇒ Object
105 106 107 |
# File 'lib/nanoc/core/item_rep.rb', line 105 def inspect "<#{self.class} name=\"#{name}\" raw_path=\"#{raw_path}\" item.identifier=\"#{item.identifier}\">" end |
#path(snapshot: :last) ⇒ Object
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.
77 78 79 |
# File 'lib/nanoc/core/item_rep.rb', line 77 def path(snapshot: :last) @paths.fetch(snapshot, []).first end |
#raw_path(snapshot: :last) ⇒ Object
Returns the item rep’s raw path. It includes the path to the output directory and the full filename.
68 69 70 |
# File 'lib/nanoc/core/item_rep.rb', line 68 def raw_path(snapshot: :last) @raw_paths.fetch(snapshot, []).first end |
#reference ⇒ Object
Returns an object that can be used for uniquely identifying objects.
97 98 99 |
# File 'lib/nanoc/core/item_rep.rb', line 97 def reference "item_rep:#{item.identifier}:#{name}" end |
#snapshot?(name) ⇒ Boolean
61 62 63 |
# File 'lib/nanoc/core/item_rep.rb', line 61 def snapshot?(name) snapshot_defs.any? { |sd| sd.name == name } end |
#to_s ⇒ Object
101 102 103 |
# File 'lib/nanoc/core/item_rep.rb', line 101 def to_s "#{item.identifier} (rep name #{name.inspect})" end |