Sha256: 9d7cdb943f0b7047ef0cccd9e0b0bf0f799e63500904a29b9632a82339d605fd

Contents?: true

Size: 856 Bytes

Versions: 2

Compression:

Stored size: 856 Bytes

Contents

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

      def check(klass)
        initialize
        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
        3
      end

      def iterate_lines!(klass)
        iterator = Iterator.new do |node|
          if node.is_a?(Rubinius::AST::InstanceVariableAccess) || node.is_a?(Rubinius::AST::InstanceVariableAssignment)
            @ivars << node.name
          end
        end
        Array(klass).each(&iterator)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pelusa-0.0.2 lib/pelusa/lint/instance_variables.rb
pelusa-0.0.1 lib/pelusa/lint/instance_variables.rb