Sha256: 7ec1a596d21b98f4f3e9bfded98820e28de4650137e48337a3b28388e40ee0ab

Contents?: true

Size: 1.56 KB

Versions: 36

Compression:

Stored size: 1.56 KB

Contents

module Inch
  module Codebase
    # ObjectsFilter can be used to filter a list of objects by a given set of
    # given +options+
    class ObjectsFilter
      # @return [API::Options::Base] the filter options
      attr_reader :options

      # @param list [Array<CodeObject::Proxy>] the unfiltered list
      # @param options [API::Options::Base] the filter options
      def initialize(list, options)
        @list = list
        @options = options
        filter
      end

      # @return [Array<CodeObject::Proxy>] the filtered list
      def objects
        @list
      end

      private

      def filter
        filter_namespaces
        filter_undocumented
        filter_depth
        filter_visibility
      end

      def filter_namespaces
        if options.namespaces == :only
          @list = @list.select(&:namespace?)
        elsif options.namespaces == :none
          @list = @list.reject(&:namespace?)
        end
      end

      def filter_undocumented
        if options.undocumented == :only
          @list = @list.select(&:undocumented?)
        elsif options.undocumented == :none
          @list = @list.reject(&:undocumented?)
        end
      end

      def filter_depth
        @list = @list.select { |o| o.depth <= options.depth } if options.depth
      end

      def filter_visibility
        @list = @list.select do |o|
          options.visibility.include?(o.visibility)
        end
        unless options.visibility.include?(:private)
          @list = @list.reject do |o|
            o.tagged_as_private?
          end
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
inch-0.9.0.rc1 lib/inch/codebase/objects_filter.rb
inch-0.8.0 lib/inch/codebase/objects_filter.rb
inch-0.8.0.rc2 lib/inch/codebase/objects_filter.rb
inch-0.8.0.rc1 lib/inch/codebase/objects_filter.rb
inch-0.7.1 lib/inch/codebase/objects_filter.rb
inch-0.7.0 lib/inch/codebase/objects_filter.rb
inch-0.6.4 lib/inch/codebase/objects_filter.rb
inch-0.6.3 lib/inch/codebase/objects_filter.rb
inch-0.6.2 lib/inch/codebase/objects_filter.rb
inch-0.6.1 lib/inch/codebase/objects_filter.rb
inch-0.6.0 lib/inch/codebase/objects_filter.rb
inch-0.6.0.rc6 lib/inch/codebase/objects_filter.rb
inch-0.6.0.rc5 lib/inch/codebase/objects_filter.rb
inch-0.6.0.rc4 lib/inch/codebase/objects_filter.rb
inch-0.6.0.rc3 lib/inch/codebase/objects_filter.rb
inch-0.6.0.rc2 lib/inch/codebase/objects_filter.rb
inch-0.6.0.rc1 lib/inch/codebase/objects_filter.rb
inch-0.5.10 lib/inch/codebase/objects_filter.rb
inch-0.5.9 lib/inch/codebase/objects_filter.rb
inch-0.5.8 lib/inch/codebase/objects_filter.rb