Sha256: 3e234df6ae540b7381162131010864de2ee3dc4b7c209b8945cb8a3da7878acc

Contents?: true

Size: 1.54 KB

Versions: 4

Compression:

Stored size: 1.54 KB

Contents

module Yardstick

  # Handle procesing a docstring or path of files
  class Processor

    # Measure files provided
    #
    # @param [Array<#to_s>, #to_s] path
    #   the files to measure
    #
    # @return [Yardstick::MeasurementSet]
    #   a collection of measurements
    #
    # @api private
    def self.process_path(path)
      YARD.parse(Array(path).map { |file| file.to_s })
      measurements
    end

    # Measure string provided
    #
    # @param [#to_str] string
    #   the string to measure
    #
    # @return [Yardstick::MeasurementSet]
    #   a collection of measurements
    #
    # @api private
    def self.process_string(string)
      YARD.parse_string(string.to_str)
      measurements
    end

    # Measure method objects in YARD registry
    #
    # @return [Yardstick::MeasurementSet]
    #   a collection of measurements
    #
    # @api private
    def self.measurements
      measurements = MeasurementSet.new
      method_objects.each do |method_object|
        measurements.merge(method_object.docstring.measure)
      end
      measurements
    end

    # Return method objects in YARD registry
    #
    # @return [Array<YARD::CodeObjects::MethodObject>]
    #   a collection of method objects
    #
    # @api private
    def self.method_objects
      YARD::Registry.all(:method).sort_by do |method_object|
        [ method_object.file, method_object.line ]
      end
    ensure
      YARD::Registry.clear
    end

    class << self
      private :measurements, :method_objects
    end

  end # class Processor
end # module Yardstick

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yardstick-0.9.2 lib/yardstick/processor.rb
yardstick-0.9.1 lib/yardstick/processor.rb
yardstick-0.9.0 lib/yardstick/processor.rb
yardstick-0.8.0 lib/yardstick/processor.rb