Sha256: 1581ba6d9ac09cf4b135886f2e1b7fab58476e5454fbdb6785640dbc1275709a

Contents?: true

Size: 1.91 KB

Versions: 4

Compression:

Stored size: 1.91 KB

Contents

# frozen-string-literal: true
#
# Copyright (C) 2019 Thomas Baron
#
# This file is part of term_utils.
#
# term_utils is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# term_utils is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with term_utils.  If not, see <https://www.gnu.org/licenses/>.
module TermUtils
  # The ff module provides a way to find files.
  module FF
    # Represents a file system query.
    class Query
      def initialize
        @config = TermUtils::FF::Config.new
      end
      def initialize_copy(other)
        @config = other.config.dup
        super
      end
      # Adds a Regexp to ignore.
      # @param regexp [Regexp]
      # @return [TermUtils::FF::Query]
      def ignore(regexp)
        @config.ignore_list << regexp
        self
      end
      # Sets a minimum depth.
      # @param depth [Integer]
      # @return [TermUtils::FF::Query]
      def min_depth(depth)
        @config.min_depth = depth
        self
      end
      # Sets a maximum depth.
      # @param depth [Integer]
      # @return [TermUtils::FF::Query]
      def max_depth(depth)
        @config.max_depth = depth
        self
      end
      # Sets whether results shall be sorted.
      # @param sorted [Boolean]
      # @return [TermUtils::FF::Query]
      def sort(sorted = true)
        @config.sorted = sorted
        self
      end
      # Executes this one.
      # @param path [String]
      # @return [TermUtils::FF::Cursor]
      def exec(path)
        TermUtils::FF::Cursor.new(@config.dup, path).bootstrap
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
term_utils-0.3.2 lib/term_utils/ff/query.rb
term_utils-0.3.1 lib/term_utils/ff/query.rb
term_utils-0.3.0 lib/term_utils/ff/query.rb
term_utils-0.2.0 lib/term_utils/ff/query.rb