Module: Sfn::Utils::Output
- Defined in:
- lib/sfn/utils/output.rb
Overview
Output Helpers
Instance Method Summary collapse
-
#get_titles(thing, args = {}) ⇒ Array<String>
Generate formatted titles.
-
#process(things, args = {}) ⇒ Object
Process things and return items.
-
#things_output(stack, things, what, *args) ⇒ Object
Output stack related things in nice format.
Instance Method Details
#get_titles(thing, args = {}) ⇒ Array<String>
Generate formatted titles
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sfn/utils/output.rb', line 37 def get_titles(thing, args = {}) attrs = args[:attributes] || [] if attrs.empty? hash = thing.is_a?(Array) ? thing.first : thing hash ||= {} attrs = hash.keys end titles = attrs.map do |key| camel(key).gsub(/([a-z])([A-Z])/, '\1 \2') end.compact if args[:format] titles.map { |s| @ui.color(s, :bold) } else titles end end |
#process(things, args = {}) ⇒ Object
TODO:
this was extracted from events and needs to be cleaned up
Process things and return items
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sfn/utils/output.rb', line 15 def process(things, args = {}) @event_ids ||= [] processed = things.reverse.map do |thing| next if @event_ids.include?(thing["id"]) @event_ids.push(thing["id"]).compact! if args[:attributes] args[:attributes].map do |key| thing[key].to_s end else thing.values end end args[:flat] ? processed.flatten : processed end |
#things_output(stack, things, what, *args) ⇒ Object
Output stack related things in nice format
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/sfn/utils/output.rb', line 60 def things_output(stack, things, what, *args) unless args.include?(:no_title) output = get_titles(things, :format => true, :attributes => allowed_attributes) else output = [] end columns = allowed_attributes.size output += process(things, :flat => true, :attributes => allowed_attributes) output.compact! if output.empty? ui.warn "No information found" unless args.include?(:ignore_empty_output) else ui.info "#{what.to_s.capitalize} for stack: #{ui.color(stack, :bold)}" if stack ui.info "#{ui.list(output, :uneven_columns_across, columns)}" end end |