Class: Rosette::Core::RepoConfigPathFilter

Inherits:
TreeFilter
  • Object
show all
Defined in:
lib/rosette/core/snapshots/repo_config_path_filter.rb

Overview

A jgit tree filter that filters by the path rules specified in the given RepoConfig.

Examples:

filter = RepoConfigPathFilter.create(repo_config)
factory = Rosette::Core::SnapshotFactory.new
  .set_repo('my_repo')

factory.add_filter(filter)
factory.take_snapshot(...)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#repo_configArray<String>

Returns the configuration to use when filtering paths.

Returns:

  • (Array<String>)

    the configuration to use when filtering paths


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rosette/core/snapshots/repo_config_path_filter.rb', line 21

class RepoConfigPathFilter < TreeFilter  # Creates a new filter with the given repo config.
  #
  # @param [RepoConfig] repo_config The configuration to use when
  #   filtering paths
  # @return [FileTypeFilter]

  def self.create(repo_config)
    # Do this because jruby is dumb (i.e. doesn't let you override java
    # constructors)
    new.tap do |obj|
      obj.repo_config = repo_config
    end
  end

  attr_accessor :repo_config

  # Overridden. Returns true if the current file matches false otherwise.
  # Generally this method is only called by Jgit internals.
  #
  # @param [Java::OrgEclipseJgitTreewalk::TreeWalk] walker The walker with
  #   the current file.
  # @return [Boolean]
  def include(walker)
    if walker.isSubtree
      true
    else
      path = walker.getPathString

      if repo_config.extractor_configs.size > 0
        repo_config.extractor_configs.any? do |extractor_config|
          extractor_config.matches?(path)
        end
      else
        true
      end
    end
  end

  # Returns true if this filter should be applied recursively, false otherwise.
  # For this particular filter, always returns true.
  #
  # @return [Boolean]
  def shouldBeRecursive
    true
  end

  # Clones this filter. For this particular filter, always returns self.
  #
  # @return [self]
  def clone
    self
  end

  # Returns a string representation of this filter.
  #
  # @return [String]
  def to_s
    "REPO_CONFIG_FILTER"
  end
end

Class Method Details

.create(repo_config) ⇒ FileTypeFilter

Creates a new filter with the given repo config.

Parameters:

  • repo_config (RepoConfig)

    The configuration to use when filtering paths

Returns:

  • (FileTypeFilter)

27
28
29
30
31
32
33
# File 'lib/rosette/core/snapshots/repo_config_path_filter.rb', line 27

def self.create(repo_config)
  # Do this because jruby is dumb (i.e. doesn't let you override java
  # constructors)
  new.tap do |obj|
    obj.repo_config = repo_config
  end
end

Instance Method Details

#cloneself

Clones this filter. For this particular filter, always returns self.

Returns:

  • (self)

70
71
72
# File 'lib/rosette/core/snapshots/repo_config_path_filter.rb', line 70

def clone
  self
end

#include(walker) ⇒ Boolean

Overridden. Returns true if the current file matches false otherwise. Generally this method is only called by Jgit internals.

Parameters:

  • walker (Java::OrgEclipseJgitTreewalk::TreeWalk)

    The walker with the current file.

Returns:

  • (Boolean)

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rosette/core/snapshots/repo_config_path_filter.rb', line 43

def include(walker)
  if walker.isSubtree
    true
  else
    path = walker.getPathString

    if repo_config.extractor_configs.size > 0
      repo_config.extractor_configs.any? do |extractor_config|
        extractor_config.matches?(path)
      end
    else
      true
    end
  end
end

#shouldBeRecursiveBoolean

Returns true if this filter should be applied recursively, false otherwise. For this particular filter, always returns true.

Returns:

  • (Boolean)

63
64
65
# File 'lib/rosette/core/snapshots/repo_config_path_filter.rb', line 63

def shouldBeRecursive
  true
end

#to_sString

Returns a string representation of this filter.

Returns:

  • (String)

77
78
79
# File 'lib/rosette/core/snapshots/repo_config_path_filter.rb', line 77

def to_s
  "REPO_CONFIG_FILTER"
end