Class: Fire::FileState

Inherits:
State
  • Object
show all
Defined in:
lib/fire/state.rb

Overview

File state.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from State

#&, #set, #|

Constructor Details

#initialize(pattern, digest, ignore) ⇒ FileState

Initialize new instance of Autologic.

Parameters:

  • pattern

    File glob or regular expression. [String,Regexp]

  • digest
  • ignore

    -



54
55
56
57
58
# File 'lib/fire/state.rb', line 54

def initialize(pattern, digest, ignore)
  @pattern = pattern
  @digest  = digest
  @ignore  = ignore
end

Instance Attribute Details

#patternObject (readonly)

File glob or regular expression.



61
62
63
# File 'lib/fire/state.rb', line 61

def pattern
  @pattern
end

Instance Method Details

#callObject

Process logic.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/fire/state.rb', line 66

def call
  result = []
  case pattern
  when Regexp
    @digest.current.keys.each do |fname|
      if md = pattern.match(fname)
        if @digest.current[fname] != @digest.saved[fname]
          result << Match.new(fname, md)
        end
      end
    end
  else
    # TODO: if fnmatch? worked like glob then we'd follow the same code as for regexp
    list = Dir[pattern].reject{ |path| @ignore.any?{ |ig| /^#{ig}/ =~ path } }
    list.each do |fname|
      if @digest.current[fname] != @digest.saved[fname]
        result << fname
      end
    end
  end
  result
end