Sha256: bee349e5c7f0bc869ce4f50267b9be0e185166275a35c6e4f80d98d62013cc2f

Contents?: true

Size: 1.34 KB

Versions: 28

Compression:

Stored size: 1.34 KB

Contents

module Inch
  module Codebase
    # ObjectsFilter can be used to filter a list of objects by given a set of
    # given +options+
    class ObjectsFilter
      attr_reader :options

      def initialize(list, options)
        @list = list
        @options = options
        filter
      end

      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
        if options.depth
          @list = @list.select { |o| o.depth <= options.depth }
        end
      end

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

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
inch-0.5.0.rc3 lib/inch/codebase/objects_filter.rb
inch-0.5.0.rc2 lib/inch/codebase/objects_filter.rb
inch-0.5.0.rc1 lib/inch/codebase/objects_filter.rb
inch-0.4.6 lib/inch/codebase/objects_filter.rb
inch-0.4.5 lib/inch/codebase/objects_filter.rb
inch-0.4.4 lib/inch/codebase/objects_filter.rb
inch-0.4.4.rc4 lib/inch/codebase/objects_filter.rb
inch-0.4.4.rc3 lib/inch/codebase/objects_filter.rb
inch-0.4.4.rc2 lib/inch/codebase/objects_filter.rb
inch-0.4.4.rc1 lib/inch/codebase/objects_filter.rb
inch-0.4.3 lib/inch/codebase/objects_filter.rb
inch-0.4.3.rc2 lib/inch/codebase/objects_filter.rb
inch-0.4.3.rc1 lib/inch/codebase/objects_filter.rb
inch-0.4.2 lib/inch/codebase/objects_filter.rb
inch-0.4.1 lib/inch/codebase/objects_filter.rb
inch-0.4.0 lib/inch/codebase/objects_filter.rb
inch-0.4.0.rc3 lib/inch/codebase/objects_filter.rb
inch-0.4.0.rc2 lib/inch/codebase/objects_filter.rb
inch-0.4.0.rc1 lib/inch/codebase/objects_filter.rb
inch-0.3.4.rc1 lib/inch/codebase/objects_filter.rb