Sha256: 149b073a1e455a3aecbdeae159b1c539a054eda422312a82ebb9aa342a0b64ee

Contents?: true

Size: 1.4 KB

Versions: 39

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module Nanoc::Int::OutdatednessRules
  class AttributesModified < Nanoc::Int::OutdatednessRule
    include Nanoc::Int::ContractsSupport

    affects_props :attributes, :compiled_content

    contract C::Or[Nanoc::Int::ItemRep, Nanoc::Int::Item, Nanoc::Int::Configuration, Nanoc::Int::Layout], C::Named['Nanoc::Int::OutdatednessChecker'] => C::Maybe[Nanoc::Int::OutdatednessReasons::Generic]
    def apply(obj, outdatedness_checker)
      case obj
      when Nanoc::Int::ItemRep
        apply(obj.item, outdatedness_checker)
      when Nanoc::Int::Item, Nanoc::Int::Layout, Nanoc::Int::Configuration
        if outdatedness_checker.checksum_store[obj] == outdatedness_checker.checksums.checksum_for(obj)
          return nil
        end

        old_checksums = outdatedness_checker.checksum_store.attributes_checksum_for(obj)
        unless old_checksums
          return Nanoc::Int::OutdatednessReasons::AttributesModified.new(true)
        end

        new_checksums = outdatedness_checker.checksums.attributes_checksum_for(obj)

        attributes = Set.new(old_checksums.keys) + Set.new(new_checksums.keys)
        changed_attributes = attributes.reject { |a| old_checksums[a] == new_checksums[a] }

        if changed_attributes.any?
          Nanoc::Int::OutdatednessReasons::AttributesModified.new(changed_attributes)
        end
      else
        raise ArgumentError
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
nanoc-4.11.0 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb
nanoc-4.10.4 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb
nanoc-4.10.3 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb
nanoc-4.10.2 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb
nanoc-4.10.1 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb
nanoc-4.10.0 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb
nanoc-4.9.9 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb
nanoc-4.9.8 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb
nanoc-4.9.7 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb
nanoc-4.9.6 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb
nanoc-4.9.5 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb
nanoc-4.9.4 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb
nanoc-4.9.3 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb
nanoc-4.9.2 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb
nanoc-4.9.1 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb
nanoc-4.9.0 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb
nanoc-4.8.19 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb
nanoc-4.8.18 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb
nanoc-4.8.17 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb
nanoc-4.8.16 lib/nanoc/base/services/outdatedness_rules/attributes_modified.rb