Class: RBI::Formatter
- Inherits:
-
Object
- Object
- RBI::Formatter
- Defined in:
- lib/rbi/formatter.rb
Instance Attribute Summary collapse
-
#max_line_length ⇒ Object
: Integer?.
Instance Method Summary collapse
-
#format_file(file) ⇒ Object
: (RBI::File file) -> void.
-
#format_tree(tree) ⇒ Object
: (RBI::Tree tree) -> void.
-
#initialize(add_sig_templates: false, group_nodes: false, max_line_length: nil, nest_singleton_methods: false, nest_non_public_members: false, sort_nodes: false, replace_attributes_with_methods: false) ⇒ Formatter
constructor
: (?add_sig_templates: bool, ?group_nodes: bool, ?max_line_length: Integer?, ?nest_singleton_methods: bool, ?nest_non_public_members: bool, ?sort_nodes: bool, ?replace_attributes_with_methods: bool) -> void.
-
#print_file(file) ⇒ Object
: (RBI::File file) -> String.
Constructor Details
#initialize(add_sig_templates: false, group_nodes: false, max_line_length: nil, nest_singleton_methods: false, nest_non_public_members: false, sort_nodes: false, replace_attributes_with_methods: false) ⇒ Formatter
: (?add_sig_templates: bool, ?group_nodes: bool, ?max_line_length: Integer?, ?nest_singleton_methods: bool, ?nest_non_public_members: bool, ?sort_nodes: bool, ?replace_attributes_with_methods: bool) -> void
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rbi/formatter.rb', line 10 def initialize( add_sig_templates: false, group_nodes: false, max_line_length: nil, nest_singleton_methods: false, nest_non_public_members: false, sort_nodes: false, replace_attributes_with_methods: 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_members = nest_non_public_members @sort_nodes = sort_nodes @replace_attributes_with_methods = replace_attributes_with_methods end |
Instance Attribute Details
#max_line_length ⇒ Object
: Integer?
7 8 9 |
# File 'lib/rbi/formatter.rb', line 7 def max_line_length @max_line_length end |
Instance Method Details
#format_file(file) ⇒ Object
: (RBI::File file) -> void
35 36 37 |
# File 'lib/rbi/formatter.rb', line 35 def format_file(file) format_tree(file.root) end |
#format_tree(tree) ⇒ Object
: (RBI::Tree tree) -> void
40 41 42 43 44 45 46 47 |
# File 'lib/rbi/formatter.rb', line 40 def format_tree(tree) tree.replace_attributes_with_methods! if @replace_attributes_with_methods tree.add_sig_templates! if @add_sig_templates tree.nest_singleton_methods! if @nest_singleton_methods tree.nest_non_public_members! if @nest_non_public_members tree.group_nodes! if @group_nodes tree.sort_nodes! if @sort_nodes end |
#print_file(file) ⇒ Object
: (RBI::File file) -> String
29 30 31 32 |
# File 'lib/rbi/formatter.rb', line 29 def print_file(file) format_file(file) file.string(max_line_length: @max_line_length) end |