Class: YES::Constraints::FNMatch

Inherits:
NodeConstraint show all
Defined in:
lib/yes/constraints/fnmatch.rb

Overview

Validate file glob match. This uess standard unix-style file matching, primarily ‘*` and `?`, to detrmine a mathing node value. All values are converted to strings (using #to_s) for comparison. – TODO: better name then `FNMatch`? ++

Instance Attribute Summary

Attributes inherited from NodeConstraint

#node

Attributes inherited from AbstractConstraint

#nodes, #spec, #tree

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NodeConstraint

#initialize, #tag, #value

Methods inherited from AbstractConstraint

#applicable?, inherited, #initialize, #match_delta, #recurse_valid?, #valid?

Constructor Details

This class inherits a constructor from YES::Constraints::NodeConstraint

Class Method Details

.applicable?(spec) ⇒ Boolean

Only applicable if ‘fnmatch` field is in spec.

Returns:

  • (Boolean)


23
24
25
# File 'lib/yes/constraints/fnmatch.rb', line 23

def self.applicable?(spec)
  spec['fnmatch']
end

.checklist(spec, tree, nodes) ⇒ Array<Constraint>

Returns:

  • (Array<Constraint>)


15
16
17
18
19
20
# File 'lib/yes/constraints/fnmatch.rb', line 15

def self.checklist(spec, tree, nodes)
  return [] unless applicable?(spec)
  nodes.map do |node|
    new(spec, tree, node)
  end
end

Instance Method Details

#validate(spec) ⇒ Boolean

Validate file glob match. This uess standard unix-style file matching, primarily ‘*` and `?`, to detrmine a mathing node value. All values are converted to strings (using #to_s) for comparison.

Returns:

  • (Boolean)

    validity



32
33
34
35
36
# File 'lib/yes/constraints/fnmatch.rb', line 32

def validate(spec)
  fnmatch = spec['fnmatch']

  File.fnmatch(fnmatch, node.value)
end