Class: Valise::PathMatcher::Pattern

Inherits:
Object
  • Object
show all
Defined in:
lib/valise/path-matcher.rb

Constant Summary collapse

FLAG_NAMES =
{
  :extended => File::FNM_EXTGLOB,
  :noextended => ~File::FNM_EXTGLOB,
  :case => ~File::FNM_CASEFOLD,
  :nocase => File::FNM_CASEFOLD,
  :pathname => File::FNM_PATHNAME,
  :nopathname => ~File::FNM_PATHNAME,
  :escape => ~File::FNM_NOESCAPE,
  :noescape => File::FNM_NOESCAPE,
  :dotmatch => File::FNM_DOTMATCH,
  :nodotmatch => ~File::FNM_DOTMATCH,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(match, include, flags) ⇒ Pattern

Returns a new instance of Pattern.



22
23
24
25
26
# File 'lib/valise/path-matcher.rb', line 22

def initialize(match, include, flags)
  @match, @include = match, include
  @flags = 0
  set_flags(flags)
end

Instance Attribute Details

#flagsObject

Returns the value of attribute flags.



27
28
29
# File 'lib/valise/path-matcher.rb', line 27

def flags
  @flags
end

#includeObject

Returns the value of attribute include.



27
28
29
# File 'lib/valise/path-matcher.rb', line 27

def include
  @include
end

#matchObject

Returns the value of attribute match.



27
28
29
# File 'lib/valise/path-matcher.rb', line 27

def match
  @match
end

Instance Method Details

#set_flags(flags) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/valise/path-matcher.rb', line 29

def set_flags(flags)
  if flags.is_a?(Array)
    flags = flags.reduce(0) do |flags, name|
      flag = FLAG_NAMES.fetch(name) do
        raise "Path match flag name #{name.inspect} not in recognized list: #{FLAG_NAMES.keys.inspect}"
      end
      if flag < 0
        flags & flag
      else
        flags | flag
      end
    end
  end
  @flags = flags
end