Class: YARDJS::Handlers::Base

Inherits:
YARD::Handlers::Base
  • Object
show all
Includes:
ParseJS::AST
Defined in:
lib/yard-js/handlers/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.handles?(node) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/yard-js/handlers/base.rb', line 9

def self.handles?(node)
  handlers.any? {|h| node.is_a?(h) }
end

Instance Method Details

#call_paramsObject



13
# File 'lib/yard-js/handlers/base.rb', line 13

def call_params; [] end

#caller_methodObject



14
# File 'lib/yard-js/handlers/base.rb', line 14

def caller_method; nil end

#clean_comment(comment) ⇒ Object



32
33
34
35
36
# File 'lib/yard-js/handlers/base.rb', line 32

def clean_comment(comment)
  comment = comment.body if comment.respond_to?(:body)
  return "" if comment.nil?
  comment.gsub(/^[ \t]*\*[ \t]{0,1}/, '')
end

#handle_default_comments(comments = statement.comments) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/yard-js/handlers/base.rb', line 20

def handle_default_comments(comments = statement.comments)
  return if comments.size == 1
  comments[0...-1].each do |comment|
    register_docstring(nil, clean_comment(comment.body))
  end

  if parser.extra_state.ignore_next_statement
    parser.extra_state.ignore_next_statement = nil
    abort!
  end
end

#parse_block(inner_node, opts = {}) ⇒ Object



16
17
18
# File 'lib/yard-js/handlers/base.rb', line 16

def parse_block(inner_node, opts = {})
  push_state(opts) { parser.process([inner_node].flatten) }
end

#register_docstring(object, docstring = statement.comments, stmt = statement) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/yard-js/handlers/base.rb', line 38

def register_docstring(object, docstring = statement.comments, stmt = statement)
  docstring = docstring.last if Array === docstring
  docstring = clean_comment(docstring) if docstring
  docstring.force_encoding('utf-8') if docstring

  super(object, docstring, stmt)
end

#register_source(object, source = statement.source, type = parser.parser_type) ⇒ Object



46
47
48
49
50
# File 'lib/yard-js/handlers/base.rb', line 46

def register_source(object, source = statement.source, type = parser.parser_type)
  return unless object.is_a?(CodeObjects::PropertyObject)
  object.source ||= source
  object.source_type = type
end