module DuckTesting::YARD

Constants

DEFAULT_PATH_GLOB

The default glob of files to be parsed.

Public Class Methods

apply(paths: DEFAULT_PATH_GLOB, excluded: []) click to toggle source

Parses a path or set of paths then prepend them into corresponding classes..

@param paths [String, Array<String>] a path, glob or list of paths to parse @param excluded [Array<String, Regexp>] a list of excluded path matchers @return [void]

# File lib/duck_testing/yard.rb, line 14
def apply(paths: DEFAULT_PATH_GLOB, excluded: [])
  Parser.parse(paths, excluded).each do |class_object|
    builder = Builder.new(class_object)
    begin
      klass = Object.const_get(class_object.path)
    rescue NameError
      next
    end
    klass.send(:prepend, builder.build(:instance))
    klass.singleton_class.send(:prepend, builder.build(:class))
  end
end
expected_types(types) click to toggle source

@param types [Array<String>] @return [Array<DuckTesting::Type::Base>]

# File lib/duck_testing/yard.rb, line 29
def expected_types(types)
  types.map do |type|
    if type == "Boolean"
      [
        DuckTesting::Type::Constant.new(true),
        DuckTesting::Type::Constant.new(false),
      ]
    elsif DuckTesting::Type::Constant::CONSTANTS.include?(type)
      DuckTesting::Type::Constant.new(type)
    elsif type == "void"
      nil
    elsif type.start_with?("Array")
      # TODO: Support specifing types of array elements.
      DuckTesting::Type::ClassInstance.new(Array)
    else
      DuckTesting::Type::ClassInstance.new(Object.const_get(type))
    end
  end.flatten.compact
end

Private Instance Methods

apply(paths: DEFAULT_PATH_GLOB, excluded: []) click to toggle source

Parses a path or set of paths then prepend them into corresponding classes..

@param paths [String, Array<String>] a path, glob or list of paths to parse @param excluded [Array<String, Regexp>] a list of excluded path matchers @return [void]

# File lib/duck_testing/yard.rb, line 14
def apply(paths: DEFAULT_PATH_GLOB, excluded: [])
  Parser.parse(paths, excluded).each do |class_object|
    builder = Builder.new(class_object)
    begin
      klass = Object.const_get(class_object.path)
    rescue NameError
      next
    end
    klass.send(:prepend, builder.build(:instance))
    klass.singleton_class.send(:prepend, builder.build(:class))
  end
end
expected_types(types) click to toggle source

@param types [Array<String>] @return [Array<DuckTesting::Type::Base>]

# File lib/duck_testing/yard.rb, line 29
def expected_types(types)
  types.map do |type|
    if type == "Boolean"
      [
        DuckTesting::Type::Constant.new(true),
        DuckTesting::Type::Constant.new(false),
      ]
    elsif DuckTesting::Type::Constant::CONSTANTS.include?(type)
      DuckTesting::Type::Constant.new(type)
    elsif type == "void"
      nil
    elsif type.start_with?("Array")
      # TODO: Support specifing types of array elements.
      DuckTesting::Type::ClassInstance.new(Array)
    else
      DuckTesting::Type::ClassInstance.new(Object.const_get(type))
    end
  end.flatten.compact
end