Class: RBI::Formatter

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/rbi/formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(add_sig_templates: false, group_nodes: false, max_line_length: nil, nest_singleton_methods: false, nest_non_public_methods: false, sort_nodes: false) ⇒ Formatter

Returns a new instance of Formatter.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rbi/formatter.rb', line 24

def initialize(
  add_sig_templates: false,
  group_nodes: false,
  max_line_length: nil,
  nest_singleton_methods: false,
  nest_non_public_methods: false,
  sort_nodes: false
)
  @add_sig_templates = add_sig_templates
  @group_nodes = group_nodes
  @max_line_length = max_line_length
  @nest_singleton_methods = nest_singleton_methods
  @nest_non_public_methods = nest_non_public_methods
  @sort_nodes = sort_nodes
end

Instance Attribute Details

#max_line_lengthObject

Returns the value of attribute max_line_length.



12
13
14
# File 'lib/rbi/formatter.rb', line 12

def max_line_length
  @max_line_length
end

#sort_nodes=(value) ⇒ Object (writeonly)

Sets the attribute sort_nodes

Parameters:

  • value

    the value to set the attribute sort_nodes to.



9
10
11
# File 'lib/rbi/formatter.rb', line 9

def sort_nodes=(value)
  @sort_nodes = value
end

Instance Method Details

#format_file(file) ⇒ Object



47
48
49
# File 'lib/rbi/formatter.rb', line 47

def format_file(file)
  format_tree(file.root)
end

#format_tree(tree) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/rbi/formatter.rb', line 52

def format_tree(tree)
  tree.add_sig_templates! if @add_sig_templates
  tree.nest_singleton_methods! if @nest_singleton_methods
  tree.nest_non_public_methods! if @nest_non_public_methods
  tree.group_nodes! if @group_nodes
  tree.sort_nodes! if @sort_nodes
end


41
42
43
44
# File 'lib/rbi/formatter.rb', line 41

def print_file(file)
  format_file(file)
  file.string(max_line_length: @max_line_length)
end