Sha256: f12d5a85c683d21bf28a0036a6b250eaa04fe0ff6c36c8d55459d361e3e7165b

Contents?: true

Size: 805 Bytes

Versions: 4

Compression:

Stored size: 805 Bytes

Contents

module Pelusa
  module Lint
    class DemeterLaw
      def initialize
        @violations = Set.new
      end

      def check(klass)
        initialize
        iterate_lines!(klass)

        return SuccessfulAnalysis.new(name) if @violations.empty?

        FailedAnalysis.new(name, @violations) do |violations|
          "There are #{violations.length} Demeter law violations in lines #{violations.to_a.join(', ')}."
        end
      end

      private

      def name
        "Respects Demeter law"
      end

      def iterate_lines!(klass)
        iterator = Iterator.new do |node|
          if node.is_a?(Rubinius::AST::Send) && node.receiver.is_a?(Rubinius::AST::Send)
            @violations << node.line
          end
        end
        Array(klass).each(&iterator)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pelusa-0.1.1 lib/pelusa/lint/demeter_law.rb
pelusa-0.1.0 lib/pelusa/lint/demeter_law.rb
pelusa-0.0.2 lib/pelusa/lint/demeter_law.rb
pelusa-0.0.1 lib/pelusa/lint/demeter_law.rb