Module: DuckTesting::YARD

Defined in:
lib/duck_testing/yard.rb,
lib/duck_testing/yard/parser.rb,
lib/duck_testing/yard/builder.rb,
lib/duck_testing/yard/code_object.rb,
lib/duck_testing/yard/class_object.rb,
lib/duck_testing/yard/method_object.rb,
lib/duck_testing/yard/method_parameter.rb

Defined Under Namespace

Classes: Builder, ClassObject, CodeObject, MethodObject, MethodParameter, Parser

Constant Summary collapse

DEFAULT_PATH_GLOB =

The default glob of files to be parsed.

["{lib,app}/**/*.rb"]

Class Method Summary collapse

Class Method Details

.apply(paths: DEFAULT_PATH_GLOB, excluded: []) ⇒ void

This method returns an undefined value.

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

Parameters:

  • paths (String, Array<String>) (defaults to: DEFAULT_PATH_GLOB)

    a path, glob or list of paths to parse

  • excluded (Array<String, Regexp>) (defaults to: [])

    a list of excluded path matchers



14
15
16
17
18
19
20
21
22
23
24
25
# 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) ⇒ Array<DuckTesting::Type::Base>

Parameters:

  • types (Array<String>)

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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