lib/nanoc/base/compilation/outdatedness_checker.rb in nanoc-4.0.2 vs lib/nanoc/base/compilation/outdatedness_checker.rb in nanoc-4.1.0a1

- old
+ new

@@ -3,29 +3,35 @@ # # @api private class OutdatednessChecker extend Nanoc::Int::Memoization - # @option params [Nanoc::Int::Site] :site (nil) The site this outdatedness - # checker belongs to. - # - # @option params [Nanoc::Int::ChecksumStore] :checksum_store (nil) The - # checksum store where checksums of items, layouts, … are stored. - # - # @option params [Nanoc::Int::DependencyTracker] :dependency_tracker (nil) The - # dependency tracker for the given site. - def initialize(params = {}) - @site = params.fetch(:site) do - raise ArgumentError, 'Nanoc::Int::OutdatednessChecker#initialize needs a :site parameter' - end - @checksum_store = params.fetch(:checksum_store) do - raise ArgumentError, 'Nanoc::Int::OutdatednessChecker#initialize needs a :checksum_store parameter' - end - @dependency_tracker = params.fetch(:dependency_tracker) do - raise ArgumentError, 'Nanoc::Int::OutdatednessChecker#initialize needs a :dependency_tracker parameter' - end + attr_reader :checksum_store + attr_reader :dependency_store + attr_reader :rule_memory_calculator + attr_reader :rule_memory_store + attr_reader :rules_collection + attr_reader :site + Reasons = Nanoc::Int::OutdatednessReasons + + # @param [Nanoc::Int::Site] site + # @param [Nanoc::Int::ChecksumStore] checksum_store + # @param [Nanoc::Int::DependencyStore] dependency_store + # @param [Nanoc::Int::RulesCollection] rules_collection + # @param [Nanoc::Int::RuleMemoryStore] rule_memory_store + # @param [Nanoc::Int::RuleMemoryCalculator] rule_memory_calculator + # @param [Nanoc::Int::ItemRepRepo] reps + def initialize(site:, checksum_store:, dependency_store:, rules_collection:, rule_memory_store:, rule_memory_calculator:, reps:) + @site = site + @checksum_store = checksum_store + @dependency_store = dependency_store + @rules_collection = rules_collection + @rule_memory_store = rule_memory_store + @rule_memory_calculator = rule_memory_calculator + @reps = reps + @basic_outdatedness_reasons = {} @outdatedness_reasons = {} @objects_outdated_due_to_dependencies = {} end @@ -43,16 +49,16 @@ # Calculates the reason why the given object is outdated. # # @param [Nanoc::Int::Item, Nanoc::Int::ItemRep, Nanoc::Int::Layout] obj The object # whose outdatedness reason should be calculated. # - # @return [Nanoc::Int::OutdatednessReasons::Generic, nil] The reason why the + # @return [Reasons::Generic, nil] The reason why the # given object is outdated, or nil if the object is not outdated. def outdatedness_reason_for(obj) reason = basic_outdatedness_reason_for(obj) if reason.nil? && outdated_due_to_dependencies?(obj) - reason = Nanoc::Int::OutdatednessReasons::DependenciesOutdated + reason = Reasons::DependenciesOutdated end reason end memoize :outdatedness_reason_for @@ -76,46 +82,46 @@ # you want to include dependencies in the outdatedness check. # # @param [Nanoc::Int::Item, Nanoc::Int::ItemRep, Nanoc::Int::Layout] obj The object # whose outdatedness reason should be calculated. # - # @return [Nanoc::Int::OutdatednessReasons::Generic, nil] The reason why the + # @return [Reasons::Generic, nil] The reason why the # given object is outdated, or nil if the object is not outdated. def basic_outdatedness_reason_for(obj) case obj when Nanoc::Int::ItemRep # Outdated if rules outdated - return Nanoc::Int::OutdatednessReasons::RulesModified if + return Reasons::RulesModified if rule_memory_differs_for(obj) # Outdated if checksums are missing or different - return Nanoc::Int::OutdatednessReasons::NotEnoughData unless checksums_available?(obj.item) - return Nanoc::Int::OutdatednessReasons::SourceModified unless checksums_identical?(obj.item) + return Reasons::NotEnoughData unless checksums_available?(obj.item) + return Reasons::SourceModified unless checksums_identical?(obj.item) # Outdated if compiled file doesn't exist (yet) - return Nanoc::Int::OutdatednessReasons::NotWritten if obj.raw_path && !File.file?(obj.raw_path) + return Reasons::NotWritten if obj.raw_path && !File.file?(obj.raw_path) # Outdated if code snippets outdated - return Nanoc::Int::OutdatednessReasons::CodeSnippetsModified if site.code_snippets.any? do |cs| + return Reasons::CodeSnippetsModified if site.code_snippets.any? do |cs| object_modified?(cs) end # Outdated if configuration outdated - return Nanoc::Int::OutdatednessReasons::ConfigurationModified if object_modified?(site.config) + return Reasons::ConfigurationModified if object_modified?(site.config) # Not outdated return nil when Nanoc::Int::Item - obj.reps.find { |rep| basic_outdatedness_reason_for(rep) } + @reps[obj].find { |rep| basic_outdatedness_reason_for(rep) } when Nanoc::Int::Layout # Outdated if rules outdated - return Nanoc::Int::OutdatednessReasons::RulesModified if + return Reasons::RulesModified if rule_memory_differs_for(obj) # Outdated if checksums are missing or different - return Nanoc::Int::OutdatednessReasons::NotEnoughData unless checksums_available?(obj) - return Nanoc::Int::OutdatednessReasons::SourceModified unless checksums_identical?(obj) + return Reasons::NotEnoughData unless checksums_available?(obj) + return Reasons::SourceModified unless checksums_identical?(obj) # Not outdated return nil else raise "do not know how to check outdatedness of #{obj.inspect}" @@ -147,11 +153,11 @@ # Don’t return true; the false will be or’ed into a true if there # really is a dependency that is causing outdatedness. return false if processed.include?(obj) # Calculate - is_outdated = dependency_tracker.objects_causing_outdatedness_of(obj).any? do |other| + is_outdated = dependency_store.objects_causing_outdatedness_of(obj).any? do |other| other.nil? || basic_outdated?(other) || outdated_due_to_dependencies?(other, processed.merge([obj])) end # Cache @objects_outdated_due_to_dependencies[obj] = is_outdated @@ -164,11 +170,11 @@ # representation to check the rule memory for # # @return [Boolean] true if the rule memory for the given item # represenation has changed, false otherwise def rule_memory_differs_for(obj) - rules_collection.rule_memory_differs_for(obj) + !rule_memory_store[obj].eql?(rule_memory_calculator[obj].serialize) end memoize :rule_memory_differs_for # @param obj # @@ -194,27 +200,7 @@ # are available and identical, false otherwise def object_modified?(obj) !checksums_available?(obj) || !checksums_identical?(obj) end memoize :object_modified? - - # @return [Nanoc::Int::ChecksumStore] The checksum store - def checksum_store - @checksum_store - end - - # @return [Nanoc::Int::RulesCollection] The rules collection - def rules_collection - site.compiler.rules_collection - end - - # @return [Nanoc::Int::DependencyTracker] The dependency tracker - def dependency_tracker - @dependency_tracker - end - - # @return [Nanoc::Int::Site] The site - def site - @site - end end end