Class: DocTypeChecker::Definition

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

Overview

DocTypeChecker::Definition

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_object) ⇒ DocTypeChecker::Definition

Parameters:

  • method_object (YARD::CodeObjects::MethodObject)


10
11
12
13
14
# File 'lib/doc_type_checker/definition.rb', line 10

def initialize(method_object)
  @name = method_object.path
  init_params(method_object)
  init_return(method_object)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/doc_type_checker/definition.rb', line 6

def name
  @name
end

#paramsObject (readonly)

Returns the value of attribute params.



6
7
8
# File 'lib/doc_type_checker/definition.rb', line 6

def params
  @params
end

#retObject (readonly)

Returns the value of attribute ret.



6
7
8
# File 'lib/doc_type_checker/definition.rb', line 6

def ret
  @ret
end

Instance Method Details

#validate_params(arguments) ⇒ Array<String>

Parameters:

  • arguments (Hash<Symbol, Class>)

Returns:

  • (Array<String>)


18
19
20
21
22
23
24
25
# File 'lib/doc_type_checker/definition.rb', line 18

def validate_params(arguments)
  params.filter_map do |key, value|
    object = arguments[key]
    unless value.valid_type(object)
      "#{name}: #{key} isn't any of #{value.inspect_type}. actual type is #{object.class}"
    end
  end
end

#validate_return(object) ⇒ String, NilClass

Parameters:

  • object (Object)

Returns:

  • (String, NilClass)


29
30
31
32
33
# File 'lib/doc_type_checker/definition.rb', line 29

def validate_return(object)
  return if !ret.types.empty? && ret.valid_type(object)

  "#{name}: return value isn't any of #{ret.inspect_type}. actual type is #{object.class}"
end