Class: YardSequel::Associations::AssociationHandler

Inherits:
YARD::Handlers::Ruby::DSLHandler
  • Object
show all
Defined in:
lib/yard-sequel/associations/association_handler.rb

Overview

The basic DSL handler class for Sequel associations.

Direct Known Subclasses

ManyToOneHandler, OneToManyHandler

Instance Method Summary collapse

Instance Method Details

#add_param_tag(method, name, class_name, description) ⇒ void (protected)

This method returns an undefined value.

Adds a parameter tag to a method object.


22
23
24
25
26
27
# File 'lib/yard-sequel/associations/association_handler.rb', line 22

def add_param_tag(method, name, class_name, description)
  method.parameters << [name, nil]
  method.docstring.add_tag(
    YARD::Tags::Tag.new(:param, description, class_name, name)
  )
end

#association_classString (protected)


30
31
32
33
34
35
36
# File 'lib/yard-sequel/associations/association_handler.rb', line 30

def association_class
  class_param = @association_options&.[](:class)
  return class_param.to_s.split('::').last if
    [String, Symbol].include? class_param.class

  association_name.classify
end

#association_class_namespaceString (protected)


39
40
41
42
43
44
45
46
47
# File 'lib/yard-sequel/associations/association_handler.rb', line 39

def association_class_namespace
  class_namespace_param = @association_options&.[](:class_namespace)
  return class_namespace_param.to_s if
    [String, Symbol].include? class_namespace_param.class

  class_param = @association_options&.[](:class)
  return class_param.to_s.rpartition('::').first if
    [String, Symbol].include? class_param.class
end

#association_full_classString (protected)


50
51
52
# File 'lib/yard-sequel/associations/association_handler.rb', line 50

def association_full_class
  [association_class_namespace, association_class].compact.join('::')
end

#association_nameString (protected)


55
56
57
# File 'lib/yard-sequel/associations/association_handler.rb', line 55

def association_name
  @statement.parameters.first.jump(:ident).source
end

#association_optionsnil, AssociationOptions (protected)


62
63
64
65
66
67
68
69
# File 'lib/yard-sequel/associations/association_handler.rb', line 62

def association_options
  option_param = @statement.parameters[1] || return
  AssociationOptions.new AstNodeHash.from_ast(option_param)
rescue ArgumentError, TypeError => error
  log.warn 'Could not parse association options due to syntax error.'
  log.debug error.message
  nil
end

#create_method_object(name) ⇒ YARD::CodeObjects::MethodObject (protected)


73
74
75
76
77
# File 'lib/yard-sequel/associations/association_handler.rb', line 73

def create_method_object(name)
  method = YARD::CodeObjects::MethodObject.new(namespace, name)
  register_and_tag method
  method
end

#processObject


8
9
10
11
# File 'lib/yard-sequel/associations/association_handler.rb', line 8

def process
  log.debug { "#{self.class.name}#process call" }
  @association_options = association_options
end

#return_tag(method, class_name, description) ⇒ void (protected)

This method returns an undefined value.

Sets or replaces the return tag on a passed method object.


84
85
86
87
88
89
# File 'lib/yard-sequel/associations/association_handler.rb', line 84

def return_tag(method, class_name, description)
  method.docstring.delete_tags(:return)
  method.docstring.add_tag(
    YARD::Tags::Tag.new(:return, description, class_name)
  )
end

#void_return_tag(method) ⇒ void (protected)

This method returns an undefined value.

Sets or replaces the return tag on a passed method object with a void return tag.


96
97
98
99
100
101
# File 'lib/yard-sequel/associations/association_handler.rb', line 96

def void_return_tag(method)
  method.docstring.delete_tags(:return)
  method.docstring.add_tag(
    YARD::Tags::Tag.new(:return, nil, 'void')
  )
end