Sha256: 5c5883cf98fd000e7fd824094ddcf4c05d7f778bdf3b415aeaef41a14a998baf

Contents?: true

Size: 940 Bytes

Versions: 13

Compression:

Stored size: 940 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 |m|
          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

13 entries across 13 versions & 1 rubygems

Version Path
reek-1.3.6 lib/reek/source/code_comment.rb
reek-1.3.5 lib/reek/source/code_comment.rb
reek-1.3.4 lib/reek/source/code_comment.rb
reek-1.3.3 lib/reek/source/code_comment.rb
reek-1.3.2 lib/reek/source/code_comment.rb
reek-1.3.1 lib/reek/source/code_comment.rb
reek-1.3 lib/reek/source/code_comment.rb
reek-1.2.13 lib/reek/source/code_comment.rb
reek-1.2.12 lib/reek/source/code_comment.rb
reek-1.2.11 lib/reek/source/code_comment.rb
reek-1.2.10 lib/reek/source/code_comment.rb
reek-1.2.9 lib/reek/source/code_comment.rb
reek-1.2.8 lib/reek/source/code_comment.rb