Sha256: e3ee49893e935e07cca90a6d158a34177587b1012ba39f4e92b0902aa3048b8f

Contents?: true

Size: 936 Bytes

Versions: 2

Compression:

Stored size: 936 Bytes

Contents

module Reek
  module Source

    #
    # A comment header from an abstract syntax tree; found directly above
    # module, class and method definitions.
    #
    class CodeComment
      CONFIG_REGEX = /:reek:(\w+)(:\s*\{.*?\})?/

      def initialize(text)
        @config =  Hash.new { |hash,key| hash[key] = {} }
        @text = text.gsub(CONFIG_REGEX) do
          add_to_config($1, $2)
          ''
        end.gsub(/#/, '').gsub(/\n/, '').strip
      end

      def config
        @config
      end

      def is_descriptive?
        @text.split(/\s+/).length >= 2
      end

    protected
      def add_to_config(smell, options)
        options ||= ': { enabled: false }'
        @config.merge! YAML.load(smell.gsub(/(?:^|_)(.)/) { $1.upcase } + options)
        # extend this to all configs --------------------------^
        # extend to allow configuration of whole smell class, not just subclass
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reek-1.3.8 lib/reek/source/code_comment.rb
reek-1.3.7 lib/reek/source/code_comment.rb