Sha256: 69430d31fd24b7e31262b1f4be97ed5d48a9f9c2ea262fcebe7d3f3d83c7c3a8

Contents?: true

Size: 860 Bytes

Versions: 1

Compression:

Stored size: 860 Bytes

Contents

module Pelusa
  module Lint
    class InstanceVariables
      def initialize
        @ivars = Set.new
      end

      def check(klass)
        iterate_lines!(klass)

        return SuccessfulAnalysis.new(name) if @ivars.length < limit

        FailedAnalysis.new(name, @ivars) do |ivars|
          "This class uses #{ivars.length} instance variables: #{ivars.to_a.join(', ')}."
        end
      end

      private

      def name
        "Uses less than #{limit} ivars"
      end

      def limit
        Pelusa.configuration['InstanceVariables'].fetch('limit', 3)
      end

      def iterate_lines!(klass)
        ClassAnalyzer.walk(klass) do |node|
          if node.is_a?(Rubinius::AST::InstanceVariableAccess) || node.is_a?(Rubinius::AST::InstanceVariableAssignment)
            @ivars << node.name
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pelusa-0.2.3 lib/pelusa/lint/instance_variables.rb