Class: Nanoc::Core::ItemRep

Inherits:
Object
  • Object
show all
Includes:
ContractsSupport
Defined in:
lib/nanoc/core/item_rep.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#compiledObject 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

#itemObject (readonly)

Returns the value of attribute item.



19
20
21
# File 'lib/nanoc/core/item_rep.rb', line 19

def item
  @item
end

#modifiedObject 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

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/nanoc/core/item_rep.rb', line 22

def name
  @name
end

#pathsObject

Returns the value of attribute paths.



16
17
18
# File 'lib/nanoc/core/item_rep.rb', line 16

def paths
  @paths
end

#raw_pathsObject

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_defsObject

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

Returns:

  • (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

#hashObject



82
83
84
# File 'lib/nanoc/core/item_rep.rb', line 82

def hash
  @hash
end

#inspectObject



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

#referenceObject

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

Returns:

  • (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_sObject



101
102
103
# File 'lib/nanoc/core/item_rep.rb', line 101

def to_s
  "#{item.identifier} (rep name #{name.inspect})"
end