Class: Wip::DockerIgnore
- Inherits:
-
Object
- Object
- Wip::DockerIgnore
- Defined in:
- lib/wip/docker_ignore.rb
Overview
Parses a .dockerignore file and decides whether a build-context-relative
path should be excluded, following the same pattern rules as the Docker
CLI (gitignore-like globs, later rules override earlier ones, ! negates).
Defined Under Namespace
Classes: Rule
Constant Summary collapse
- FNMATCH_FLAGS =
File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #ignored?(relative_path) ⇒ Boolean
-
#initialize(lines) ⇒ DockerIgnore
constructor
A new instance of DockerIgnore.
Constructor Details
#initialize(lines) ⇒ DockerIgnore
Returns a new instance of DockerIgnore.
21 22 23 |
# File 'lib/wip/docker_ignore.rb', line 21 def initialize(lines) @rules = lines.filter_map { |line| parse(line) } end |
Class Method Details
.load(path) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/wip/docker_ignore.rb', line 14 def self.load(path) path = Pathname(path) return new([]) unless path.file? new(path.readlines) end |
Instance Method Details
#empty? ⇒ Boolean
25 |
# File 'lib/wip/docker_ignore.rb', line 25 def empty? = @rules.empty? |
#ignored?(relative_path) ⇒ Boolean
27 28 29 30 31 |
# File 'lib/wip/docker_ignore.rb', line 27 def ignored?(relative_path) @rules.reduce(false) do |ignored, rule| matches?(rule.pattern, relative_path) ? !rule.negate : ignored end end |