Class: EditorConfigGenerator::EditorConfig
- Inherits:
-
Object
- Object
- EditorConfigGenerator::EditorConfig
- Defined in:
- lib/editorconfig/editor_config.rb
Overview
Object representation of an EditorConfig file rubocop:disable Style/AccessorMethodName
Instance Attribute Summary collapse
-
#charset ⇒ Object
readonly
Returns the value of attribute charset.
-
#end_of_line ⇒ Object
readonly
Returns the value of attribute end_of_line.
-
#file_type ⇒ Object
readonly
Returns the value of attribute file_type.
-
#indent_size ⇒ Object
readonly
Returns the value of attribute indent_size.
-
#indent_style ⇒ Object
readonly
Returns the value of attribute indent_style.
-
#insert_final_newline ⇒ Object
readonly
Returns the value of attribute insert_final_newline.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#trim_trailing_whitespace ⇒ Object
readonly
Returns the value of attribute trim_trailing_whitespace.
Instance Method Summary collapse
- #append_charset_to_s(config_string) ⇒ Object
- #append_end_of_line_to_s(config_string) ⇒ Object
- #append_file_type_to_s(config_string) ⇒ Object
- #append_final_newline_to_s(config_string) ⇒ Object
- #append_indent_size_to_s(config_string) ⇒ Object
- #append_indent_style_to_s(config_string) ⇒ Object
- #append_root_to_s(config_string) ⇒ Object
- #append_whitespace_to_s(config_string) ⇒ Object
- #defaults? ⇒ Boolean
-
#initialize(options = {}) ⇒ EditorConfig
constructor
A new instance of EditorConfig.
- #minimum? ⇒ Boolean
- #set_charset_option(options) ⇒ Object
- #set_end_of_line_option(options) ⇒ Object
- #set_file_type_option(options) ⇒ Object
- #set_final_newline_option(options) ⇒ Object
- #set_indent_size_option(options) ⇒ Object
- #set_indent_style_option(options) ⇒ Object
- #set_options(options) ⇒ Object
- #set_root_option(options) ⇒ Object
- #set_trailing_space_option(options) ⇒ Object
- #to_s ⇒ Object
- #to_s_without_line(line_identifier) ⇒ Object
- #to_s_without_root ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ EditorConfig
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/editorconfig/editor_config.rb', line 9 def initialize( = {}) @root = nil @file_type = :* @indent_style = nil @end_of_line = nil @charset = nil @trim_trailing_whitespace = nil @insert_final_newline = nil OptionTransformer.() () end |
Instance Attribute Details
#charset ⇒ Object (readonly)
Returns the value of attribute charset.
5 6 7 |
# File 'lib/editorconfig/editor_config.rb', line 5 def charset @charset end |
#end_of_line ⇒ Object (readonly)
Returns the value of attribute end_of_line.
5 6 7 |
# File 'lib/editorconfig/editor_config.rb', line 5 def end_of_line @end_of_line end |
#file_type ⇒ Object (readonly)
Returns the value of attribute file_type.
5 6 7 |
# File 'lib/editorconfig/editor_config.rb', line 5 def file_type @file_type end |
#indent_size ⇒ Object (readonly)
Returns the value of attribute indent_size.
5 6 7 |
# File 'lib/editorconfig/editor_config.rb', line 5 def indent_size @indent_size end |
#indent_style ⇒ Object (readonly)
Returns the value of attribute indent_style.
5 6 7 |
# File 'lib/editorconfig/editor_config.rb', line 5 def indent_style @indent_style end |
#insert_final_newline ⇒ Object (readonly)
Returns the value of attribute insert_final_newline.
5 6 7 |
# File 'lib/editorconfig/editor_config.rb', line 5 def insert_final_newline @insert_final_newline end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
5 6 7 |
# File 'lib/editorconfig/editor_config.rb', line 5 def root @root end |
#trim_trailing_whitespace ⇒ Object (readonly)
Returns the value of attribute trim_trailing_whitespace.
5 6 7 |
# File 'lib/editorconfig/editor_config.rb', line 5 def trim_trailing_whitespace @trim_trailing_whitespace end |
Instance Method Details
#append_charset_to_s(config_string) ⇒ Object
97 98 99 100 |
# File 'lib/editorconfig/editor_config.rb', line 97 def append_charset_to_s(config_string) return if @charset.nil? config_string << "charset = #{@charset}\n" end |
#append_end_of_line_to_s(config_string) ⇒ Object
102 103 104 105 |
# File 'lib/editorconfig/editor_config.rb', line 102 def append_end_of_line_to_s(config_string) return if @end_of_line.nil? config_string << "end_of_line = #{@end_of_line}\n" end |
#append_file_type_to_s(config_string) ⇒ Object
117 118 119 |
# File 'lib/editorconfig/editor_config.rb', line 117 def append_file_type_to_s(config_string) config_string << "[#{@file_type}]\n" end |
#append_final_newline_to_s(config_string) ⇒ Object
86 87 88 89 |
# File 'lib/editorconfig/editor_config.rb', line 86 def append_final_newline_to_s(config_string) return if @insert_final_newline.nil? config_string << "insert_final_newline = #{@insert_final_newline}\n" end |
#append_indent_size_to_s(config_string) ⇒ Object
107 108 109 110 |
# File 'lib/editorconfig/editor_config.rb', line 107 def append_indent_size_to_s(config_string) return if @indent_size.nil? config_string << "indent_size = #{@indent_size}\n" end |
#append_indent_style_to_s(config_string) ⇒ Object
112 113 114 115 |
# File 'lib/editorconfig/editor_config.rb', line 112 def append_indent_style_to_s(config_string) return if @indent_style.nil? config_string << "indent_style = #{@indent_style}\n" end |
#append_root_to_s(config_string) ⇒ Object
121 122 123 124 |
# File 'lib/editorconfig/editor_config.rb', line 121 def append_root_to_s(config_string) return if @root.nil? config_string << "root = #{@root}\n" end |
#append_whitespace_to_s(config_string) ⇒ Object
91 92 93 94 95 |
# File 'lib/editorconfig/editor_config.rb', line 91 def append_whitespace_to_s(config_string) return if @trim_trailing_whitespace.nil? config_string << 'trim_trailing_whitespace ' \ "= #{@trim_trailing_whitespace}\n" end |
#defaults? ⇒ Boolean
149 150 151 152 153 |
# File 'lib/editorconfig/editor_config.rb', line 149 def defaults? minimum? && @file_type == :* && @root.nil? end |
#minimum? ⇒ Boolean
139 140 141 142 143 144 145 146 147 |
# File 'lib/editorconfig/editor_config.rb', line 139 def minimum? # The minimum editor config file is one with only root and file_type set @indent_style.nil? && @indent_size.nil? && @end_of_line.nil? && @charset.nil? && @trim_trailing_whitespace.nil? && @insert_final_newline.nil? end |
#set_charset_option(options) ⇒ Object
48 49 50 51 |
# File 'lib/editorconfig/editor_config.rb', line 48 def set_charset_option() return if [:charset].nil? @charset = [:charset] end |
#set_end_of_line_option(options) ⇒ Object
53 54 55 56 |
# File 'lib/editorconfig/editor_config.rb', line 53 def set_end_of_line_option() return if [:end_of_line].nil? @end_of_line = [:end_of_line] end |
#set_file_type_option(options) ⇒ Object
33 34 35 36 |
# File 'lib/editorconfig/editor_config.rb', line 33 def set_file_type_option() return if [:file_type].nil? @file_type = [:file_type] end |
#set_final_newline_option(options) ⇒ Object
38 39 40 41 |
# File 'lib/editorconfig/editor_config.rb', line 38 def set_final_newline_option() return if [:insert_final_newline].nil? @insert_final_newline = [:insert_final_newline] end |
#set_indent_size_option(options) ⇒ Object
58 59 60 61 |
# File 'lib/editorconfig/editor_config.rb', line 58 def set_indent_size_option() return if [:indent_size].nil? @indent_size = [:indent_size] end |
#set_indent_style_option(options) ⇒ Object
63 64 65 66 |
# File 'lib/editorconfig/editor_config.rb', line 63 def set_indent_style_option() return if [:indent_style].nil? @indent_style = [:indent_style] end |
#set_options(options) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/editorconfig/editor_config.rb', line 22 def () set_root_option() set_indent_style_option() set_indent_size_option() set_end_of_line_option() set_charset_option() set_trailing_space_option() set_final_newline_option() set_file_type_option() end |
#set_root_option(options) ⇒ Object
68 69 70 71 |
# File 'lib/editorconfig/editor_config.rb', line 68 def set_root_option() return if [:root].nil? @root = [:root] end |
#set_trailing_space_option(options) ⇒ Object
43 44 45 46 |
# File 'lib/editorconfig/editor_config.rb', line 43 def set_trailing_space_option() return if [:trim_trailing_whitespace].nil? @trim_trailing_whitespace = [:trim_trailing_whitespace] end |
#to_s ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/editorconfig/editor_config.rb', line 73 def to_s config_string = '' append_root_to_s(config_string) append_file_type_to_s(config_string) append_indent_style_to_s(config_string) append_indent_size_to_s(config_string) append_end_of_line_to_s(config_string) append_charset_to_s(config_string) append_whitespace_to_s(config_string) append_final_newline_to_s(config_string) config_string end |
#to_s_without_line(line_identifier) ⇒ Object
132 133 134 135 136 137 |
# File 'lib/editorconfig/editor_config.rb', line 132 def to_s_without_line(line_identifier) lines = to_s.lines index = lines.index(line_identifier) lines.delete_at index lines.join end |
#to_s_without_root ⇒ Object
126 127 128 129 130 |
# File 'lib/editorconfig/editor_config.rb', line 126 def to_s_without_root lines = to_s.lines lines.delete_at 0 lines.join end |