Sha256: 4b5f3f91c2aed2716d7bc14cbbf3cc1fdbd0b386233e0c3284f08f72d202d0e9

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

module Reek
  class Source
    #
    # Factory method: creates a +Source+ from obj.
    # The code is not parsed until +report+ is called.
    # (This feature is only enabled if you have the ParseTree gem installed.)
    #
    def self.from_object(obj)
      return ObjectSource.new(obj, obj.to_s)
    end
  end

  class ObjectSource < Source   # :nodoc:

    def self.unify(sexp)   # :nodoc:
      unifier = Unifier.new
      unifier.processors.each do |proc|
        proc.unsupported.delete :cfunc # HACK
      end
      return unifier.process(sexp[0])
    end

    def initialize(code, desc)     # :nodoc:
      super
      @cf.disable('LargeClass')
    end

    def can_parse_objects?
      return true if Object.const_defined?(:ParseTree)
      begin
        require 'parse_tree'
        true
      rescue LoadError
        false
      end
    end

    def generate_syntax_tree
      if can_parse_objects?
        ObjectSource.unify(ParseTree.new.parse_tree(@source))
      else
        throw ArgumentError.new('You must install the ParseTree gem to use this feature')
      end
    end
  end
end

class Object
  #
  # Constructs a Source representing this object; the source can then be used
  # to generate an abstract syntax tree for the object, which can in turn then
  # be examined for code smells.
  # (This feature is only enabled if you have the ParseTree gem installed.)
  #
  def to_source
    Reek::Source.from_object(self)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kevinrutherford-reek-1.1.3.2 lib/reek/object_source.rb