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

#inspectObject



87
88
89
# File 'lib/nanoc/core/item_rep.rb', line 87

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.



74
75
76
# File 'lib/nanoc/core/item_rep.rb', line 74

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.



65
66
67
# File 'lib/nanoc/core/item_rep.rb', line 65

def raw_path(snapshot: :last)
  @raw_paths.fetch(snapshot, []).first
end

#referenceObject

Returns an object that can be used for uniquely identifying objects.



79
80
81
# File 'lib/nanoc/core/item_rep.rb', line 79

def reference
  "item_rep:#{item.identifier}:#{name}"
end

#snapshot?(name) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/nanoc/core/item_rep.rb', line 58

def snapshot?(name)
  snapshot_defs.any? { |sd| sd.name == name }
end

#to_sObject



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

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