Class: Blufin::YmlOutputter
- Inherits:
-
Object
- Object
- Blufin::YmlOutputter
- Includes:
- Columnist
- Defined in:
- lib/core/yml/yml_outputter.rb
Constant Summary collapse
- AUTO =
'AUTO'
- CUSTOM =
'CUSTOM'
- SYSTEM =
'SYSTEM'
Instance Method Summary collapse
- #add_auto_increment_indexed_table(schema, table, amount) ⇒ Object
- #add_auto_increment_table(schema, table) ⇒ Object
- #add_resource(key, data) ⇒ Object
-
#initialize(site) ⇒ YmlOutputter
constructor
A new instance of YmlOutputter.
- #set_schema_fks_links(hash) ⇒ Object
-
#show_auto_increment ⇒ Object
Renders the AUTO_INCREMENT table.
-
#show_enums ⇒ Object
Renders a summary of all enums that are available (including their possible values).
-
#show_resources(as_json = false) ⇒ Object
Renders a summary of all resource end-points exposed by the API.
Constructor Details
#initialize(site) ⇒ YmlOutputter
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/core/yml/yml_outputter.rb', line 11 def initialize(site) @site = Blufin::SiteResolver::validate_site(site) @auto_increment = [] @auto_increment_indexed = [] @resources = [] @schema_fks_links = {} @yml_enum_scanner = Blufin::ScannerJavaEnums.new(@site) end |
Instance Method Details
#add_auto_increment_indexed_table(schema, table, amount) ⇒ Object
206 207 208 |
# File 'lib/core/yml/yml_outputter.rb', line 206 def add_auto_increment_indexed_table(schema, table, amount) @auto_increment_indexed << "(#{amount}) \xe2\x86\x92 #{schema}.#{table}" end |
#add_auto_increment_table(schema, table) ⇒ Object
202 203 204 |
# File 'lib/core/yml/yml_outputter.rb', line 202 def add_auto_increment_table(schema, table) @auto_increment << "#{schema}.#{table}" end |
#add_resource(key, data) ⇒ Object
210 211 212 |
# File 'lib/core/yml/yml_outputter.rb', line 210 def add_resource(key, data) @resources << {key => data} end |
#set_schema_fks_links(hash) ⇒ Object
214 215 216 |
# File 'lib/core/yml/yml_outputter.rb', line 214 def set_schema_fks_links(hash) @schema_fks_links = hash end |
#show_auto_increment ⇒ Object
Renders the AUTO_INCREMENT table.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/core/yml/yml_outputter.rb', line 28 def show_auto_increment cnt = 0 max = [@auto_increment.length, @auto_increment_indexed.length].max.to_i Blufin::Terminal::custom('SUMMARY', 23, Blufin::YmlSchemaValidator::FLAG_AUTO_INCREMENT, "Below you can see which tables have what #{Blufin::Terminal::format_highlight(Blufin::YmlSchemaValidator::FLAG_AUTO_INCREMENT)} values applied") table(:border => false) do row do column('', :width => 4) column('AUTO_INCREMENT', :width => 60, :color => 34) column('AUTO_INCREMENT(?)', :width => 60, :color => 34) end while cnt + 1 < max row do column('') column(@auto_increment[cnt], :color => 240) column(@auto_increment_indexed[cnt], :color => 240) end cnt = cnt + 1 end end puts "\x1B[0m" end |
#show_enums ⇒ Object
Renders a summary of all enums that are available (including their possible values).
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/core/yml/yml_outputter.rb', line 59 def show_enums terminal_width = Blufin::Terminal::get_terminal_width Blufin::Terminal::error('Cannot display data because terminal window is too narrow.', ["Current width is: #{Blufin::Terminal::format_highlight(terminal_width)}", "Minimum width is: #{Blufin::Terminal::format_highlight('90')}"], true) if terminal_width < 90 && all Blufin::Terminal::custom('SUMMARY', 58, 'ENUMS', "Below is a list of all available #{Blufin::Terminal::format_highlight('ENUMS')} for \x1B[38;5;106m#{Blufin::SiteResolver::get_site_title(@site)}\x1B[0m.") terminal_width = Blufin::Terminal::get_terminal_width all_enums = [] auto_enums = @yml_enum_scanner.get_auto_enums custom_enums = @yml_enum_scanner.get_custom_enums system_enums = @yml_enum_scanner.get_system_enums auto_enums.keys.each { |enum| all_enums << enum } custom_enums.keys.each { |enum| all_enums << enum } system_enums.keys.each { |enum| all_enums << enum } max_enum_width = all_enums.max_by(&:length).length value_column_max_width = terminal_width - 30 - max_enum_width enum_column_width = ((max_enum_width + 5) < 10) ? 10 : (max_enum_width + 5) table(:border => false) do row do column('', :width => 17, :align => 'right') column('', :width => 1, :color => 255) column('', :width => enum_column_width, :color => 240, :align => 'left') column('', :width => value_column_max_width) end show_enums_common_table(custom_enums, value_column_max_width, AUTO) show_enums_common_table(auto_enums, value_column_max_width, CUSTOM) show_enums_common_table(system_enums, value_column_max_width, SYSTEM) end end |
#show_resources(as_json = false) ⇒ Object
Renders a summary of all resource end-points exposed by the API.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/core/yml/yml_outputter.rb', line 103 def show_resources(as_json = false) if @resources.any? if as_json puts @resources.inspect else width_schema = [] width_group = [] width_resource = [] width_type = [] # Get column widths (to make as narrow as possible). @resources.each do |data| data.each do |key, resource| width_schema << resource[:schema].length width_group << resource[:resource].split('/')[0].length width_resource << resource[:resource].length width_type << resource[:type].length end end Blufin::Terminal::custom('SUMMARY', 161, 'RESOURCES', "Below is a summary of the final #{Blufin::Terminal::format_highlight('RESOURCE STRUCTURE')}") table(:border => false) do current_group = nil @resources.each do |data| data.each do |key, resource| group = resource[:resource].split('/')[0] extra = '' extra_color = 240 case resource[:type] when Blufin::YmlSchemaValidator::RESOURCE_TYPE_PARENT type_text = "\xe2\x80\x94" type_color = 240 when Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT type_text = Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT type_color = 147 when Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT_LIST type_text = Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT_LIST type_color = 197 when Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT_LINK type_text = Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT_LINK type_color = 118 else raise RuntimeError, "Type not found in \xe2\x86\x92 show_resources()." end # If this is a LINKED table, show list of tables where it's referenced from. if resource[:type] == Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT_LINK unless @schema_fks_links[key].nil? extra = [] @schema_fks_links[key].each do |table| extra << table.split('.')[1] end extra = "\xe2\x86\x92 #{extra.join(', ')}" extra_color = 220 end end row do column((group != current_group) ? "#{resource[:schema]} \xe2\x86\x92" : '', :color => 250, :width => (width_schema.max.to_i) + 4, :align => 'right') column((group != current_group) ? group : '', :color => 154, :width => (width_group.max.to_i) + 2) column(resource[:resource], :color => 240, :width => (width_resource.max.to_i) + 2) column("#{type_text}", :color => type_color, :width => width_type.max.to_i, :align => 'right') column(extra, :color => extra_color, :width => 100) end current_group = group current_schema = resource[:schema] end end row do column('') column('') column('') column('') column('') end end end end end |