Sha256: 3c0b86cc7339f992a98464f3c0dd56de9f0d1dde36735031d151b8e6e96c2f3c

Contents?: true

Size: 901 Bytes

Versions: 7

Compression:

Stored size: 901 Bytes

Contents

require 'yaml'
require 'private_attr/everywhere'

# NOTE: Work-around for https://github.com/tenderlove/psych/issues/223
require 'psych.rb' if Object.const_defined?(:Psych)

module Reek
  #
  # 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
        @config.merge! add_to_config($1, $2)
        ''
      end.gsub(/#/, '').gsub(/\n/, '').strip
    end

    attr_reader :config

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

    private

    # :reek:UtilityFunction
    def add_to_config(smell, options)
      options ||= ': { enabled: false }'
      YAML.load(smell + options)
    end

    private_attr_reader :text
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
reek-3.7.1 lib/reek/code_comment.rb
reek-3.7.0 lib/reek/code_comment.rb
reek-3.6.1 lib/reek/code_comment.rb
reek-3.6.0 lib/reek/code_comment.rb
reek-3.5.0 lib/reek/code_comment.rb
reek-3.4.1 lib/reek/code_comment.rb
reek-3.4.0 lib/reek/code_comment.rb