Class: DocTypeChecker::TagType

Inherits:
Object
  • Object
show all
Defined in:
lib/doc_type_checker/tag_type.rb

Overview

DocTypeChecker::TagType

Constant Summary collapse

ALLOW_TAG_NAMES =
%w[param return].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag) ⇒ DocTypeChecker::TagType

Parameters:

  • tag (YARD::Tags::Tag)

Raises:

  • (ArgumentError)

11
12
13
14
15
# File 'lib/doc_type_checker/tag_type.rb', line 11

def initialize(tag)
  raise ArgumentError unless ALLOW_TAG_NAMES.include?(tag.tag_name)

  @types = tag.types.to_a.flat_map.filter_map { |type_comment| const_get(type_comment) }
end

Instance Attribute Details

#typesObject (readonly)

Returns the value of attribute types.


7
8
9
# File 'lib/doc_type_checker/tag_type.rb', line 7

def types
  @types
end

Instance Method Details

#inspect_typeString

Returns:

  • (String)

24
25
26
# File 'lib/doc_type_checker/tag_type.rb', line 24

def inspect_type
  types.join(', ')
end

#valid_type(object) ⇒ TrueClass, FalseClass

Parameters:

  • object (Object)

Returns:

  • (TrueClass, FalseClass)

19
20
21
# File 'lib/doc_type_checker/tag_type.rb', line 19

def valid_type(object)
  types.any? { |type| object.is_a?(type) }
end