Sha256: f0649d3dfc0a457f18059217435140b74e631f4fd9e2ce9513951bcd385d1c5f

Contents?: true

Size: 745 Bytes

Versions: 2

Compression:

Stored size: 745 Bytes

Contents

module Pelusa
  module Lint
    class LineRestriction
      def initialize
        @lines = Set.new
      end

      def check(klass)
        iterate_lines!(klass)

        return SuccessfulAnalysis.new(name) if lines < limit

        FailedAnalysis.new(name, lines) do |lines|
          "This class has #{lines} lines."
        end
      end

      private

      def name
        "Is below #{limit} lines"
      end

      def limit
        Pelusa.configuration['LineRestriction'].fetch('limit', 50)
      end

      def lines
        @lines.max - @lines.min
      end

      def iterate_lines!(klass)
        ClassAnalyzer.walk(klass) do |node|
          @lines << node.line if node.respond_to?(:line)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pelusa-0.2.4 lib/pelusa/lint/line_restriction.rb
pelusa-0.2.3 lib/pelusa/lint/line_restriction.rb