Sha256: 398006f0f7611bee86f19f64dfff47ff23793cf31f1fc68ce52108d17353918f

Contents?: true

Size: 1.28 KB

Versions: 327

Compression:

Stored size: 1.28 KB

Contents

module FSSM::State
  class Directory
    attr_reader :path

    def initialize(path)
      @path = path
      @cache = FSSM::Tree::Cache.new
    end

    def refresh(base=nil, skip_callbacks=false)
      previous, current = recache(base || @path.to_pathname)

      unless skip_callbacks
        deleted(previous, current)
        created(previous, current)
        modified(previous, current)
      end
    end

    private

    def created(previous, current)
      (current.keys - previous.keys).each {|created| @path.create(created)}
    end

    def deleted(previous, current)
      (previous.keys - current.keys).each {|deleted| @path.delete(deleted)}
    end

    def modified(previous, current)
      (current.keys & previous.keys).each do |file|
        @path.update(file) if (current[file] <=> previous[file]) != 0
      end
    end

    def recache(base)
      base = FSSM::Pathname.for(base)
      previous = @cache.files
      snapshot(base)
      current = @cache.files
      [previous, current]
    end

    def snapshot(base)
      base = FSSM::Pathname.for(base)
      @cache.unset(base)
      @path.glob.each {|glob| add_glob(base, glob)}
    end

    def add_glob(base, glob)
      FSSM::Pathname.glob(base.join(glob).to_s).each do |fn|
        @cache.set(fn)
      end
    end

  end
end

Version data entries

327 entries across 327 versions & 7 rubygems

Version Path
haml-3.1.3 vendor/sass/vendor/fssm/lib/fssm/state/directory.rb
haml-3.2.0.alpha.8 vendor/sass/vendor/fssm/lib/fssm/state/directory.rb
sass-3.1.4 vendor/fssm/lib/fssm/state/directory.rb
sass-3.2.0.alpha.11 vendor/fssm/lib/fssm/state/directory.rb
sass-3.1.3 vendor/fssm/lib/fssm/state/directory.rb
sass-3.2.0.alpha.9 vendor/fssm/lib/fssm/state/directory.rb
sass-3.2.0.alpha.8 vendor/fssm/lib/fssm/state/directory.rb
haml-3.2.0.alpha.5 vendor/sass/vendor/fssm/lib/fssm/state/directory.rb
haml-3.2.0.alpha.4 vendor/sass/vendor/fssm/lib/fssm/state/directory.rb
haml-3.1.2 vendor/sass/vendor/fssm/lib/fssm/state/directory.rb
sass-3.1.2 vendor/fssm/lib/fssm/state/directory.rb
sass-3.2.0.alpha.7 vendor/fssm/lib/fssm/state/directory.rb
sass-3.2.0.alpha.6 vendor/fssm/lib/fssm/state/directory.rb
radiant-1.0.0.rc1 vendor/plugins/haml/vendor/fssm/lib/fssm/state/directory.rb
haml-3.2.0.alpha.3 vendor/sass/vendor/fssm/lib/fssm/state/directory.rb
sass-3.2.0.alpha.4 vendor/fssm/lib/fssm/state/directory.rb
sass-3.2.0.alpha.3 vendor/fssm/lib/fssm/state/directory.rb
sass-3.1.1 vendor/fssm/lib/fssm/state/directory.rb
haml-3.2.0.alpha.2 vendor/sass/vendor/fssm/lib/fssm/state/directory.rb
haml-3.1.1 vendor/sass/vendor/fssm/lib/fssm/state/directory.rb