Class: Nanoc::Core::BasicOutdatednessChecker

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

Constant Summary collapse

Rules =
Nanoc::Core::OutdatednessRules
RULES_FOR_ITEM_REP =
[
  Rules::ItemAdded,
  Rules::RulesModified,
  Rules::ContentModified,
  Rules::AttributesModified,
  Rules::NotWritten,
  Rules::CodeSnippetsModified,
  Rules::UsesAlwaysOutdatedFilter,
].freeze
RULES_FOR_LAYOUT =
[
  Rules::LayoutAdded,
  Rules::RulesModified,
  Rules::ContentModified,
  Rules::AttributesModified,
  Rules::UsesAlwaysOutdatedFilter,
].freeze
RULES_FOR_CONFIG =
[
  Rules::AttributesModified,
].freeze
C_OBJ =
C_OBJ_MAYBE_REP =
C_ACTION_SEQUENCES =

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ContractsSupport

enabled?, included, setup_once, warn_about_performance

Constructor Details

#initialize(site:, checksum_store:, checksums:, dependency_store:, action_sequence_store:, action_sequences:, reps:) ⇒ BasicOutdatednessChecker

Returns a new instance of BasicOutdatednessChecker.



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/nanoc/core/basic_outdatedness_checker.rb', line 70

def initialize(site:, checksum_store:, checksums:, dependency_store:, action_sequence_store:, action_sequences:, reps:)
  @reps = reps
  @site = site
  @checksum_store = checksum_store
  @checksums = checksums
  @dependency_store = dependency_store
  @action_sequence_store = action_sequence_store
  @action_sequences = action_sequences

  # Memoize
  @_outdatedness_status_for = {}
end

Instance Attribute Details

#action_sequence_storeObject (readonly)

Returns the value of attribute action_sequence_store.



12
13
14
# File 'lib/nanoc/core/basic_outdatedness_checker.rb', line 12

def action_sequence_store
  @action_sequence_store
end

#action_sequencesObject (readonly)

Returns the value of attribute action_sequences.



13
14
15
# File 'lib/nanoc/core/basic_outdatedness_checker.rb', line 13

def action_sequences
  @action_sequences
end

#checksum_storeObject (readonly)

Returns the value of attribute checksum_store.



9
10
11
# File 'lib/nanoc/core/basic_outdatedness_checker.rb', line 9

def checksum_store
  @checksum_store
end

#checksumsObject (readonly)

Returns the value of attribute checksums.



10
11
12
# File 'lib/nanoc/core/basic_outdatedness_checker.rb', line 10

def checksums
  @checksums
end

#dependency_storeObject (readonly)

Returns the value of attribute dependency_store.



11
12
13
# File 'lib/nanoc/core/basic_outdatedness_checker.rb', line 11

def dependency_store
  @dependency_store
end

#siteObject (readonly)

Returns the value of attribute site.



8
9
10
# File 'lib/nanoc/core/basic_outdatedness_checker.rb', line 8

def site
  @site
end

Instance Method Details

#action_sequence_for(rep) ⇒ Object



105
106
107
# File 'lib/nanoc/core/basic_outdatedness_checker.rb', line 105

def action_sequence_for(rep)
  @action_sequences.fetch(rep)
end

#outdatedness_status_for(obj) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/nanoc/core/basic_outdatedness_checker.rb', line 84

def outdatedness_status_for(obj)
  # TODO: remove memoization (no longer needed)
  @_outdatedness_status_for[obj] ||=
    case obj
    when Nanoc::Core::ItemRep
      apply_rules(RULES_FOR_ITEM_REP, obj)
    when Nanoc::Core::Item
      apply_rules_multi(RULES_FOR_ITEM_REP, @reps[obj])
    when Nanoc::Core::Layout
      apply_rules(RULES_FOR_LAYOUT, obj)
    when Nanoc::Core::Configuration
      apply_rules(RULES_FOR_CONFIG, obj)
    when Nanoc::Core::ItemCollection, Nanoc::Core::LayoutCollection
      # Collections are never outdated. Objects inside them might be,
      # however.
      apply_rules([], obj)
    else
      raise Nanoc::Core::Errors::InternalInconsistency, "do not know how to check outdatedness of #{obj.inspect}"
    end
end