module SexySettings::Printable

This module holds print methods

Public Instance Methods

as_formatted_text(which = :all) click to toggle source
# File lib/sexy_settings/printable.rb, line 5
def as_formatted_text(which = :all)
  props_list = property_list(which)
  max_key_size = props_list.map { |el| el.first.to_s.size }.max
  [
    sharp_line(which),
    title(which),
    sharp_line(which),
    '',
    formatted_properties(props_list, max_key_size),
    ''
  ].join("\n")
end

Private Instance Methods

formatted_properties(data, max_key_size) click to toggle source
# File lib/sexy_settings/printable.rb, line 41
def formatted_properties(data, max_key_size)
  data.sort_by(&:first).map do |(prop, value)|
    value = protect_sensitive_data(prop, value)
    "#{indent}#{prop}#{indent + indent(max_key_size - prop.to_s.size)}=#{indent}#{value}"
  end
end
indent(space_count = nil) click to toggle source
# File lib/sexy_settings/printable.rb, line 28
def indent(space_count = nil)
  ' ' * (space_count.nil? ? 2 : space_count)
end
property_list(which) click to toggle source
# File lib/sexy_settings/printable.rb, line 32
def property_list(which)
  case which
  when :all then @all
  when :custom then @custom
  when :default then @default
  else ''
  end.to_a
end
protect_sensitive_data(prop, value) click to toggle source
# File lib/sexy_settings/printable.rb, line 48
def protect_sensitive_data(prop, value)
  SensitiveDataProtector.new(prop, value).protected_value
end
sharp_line(which) click to toggle source
# File lib/sexy_settings/printable.rb, line 20
def sharp_line(which)
  '#' * title(which).size
end
title(which) click to toggle source
# File lib/sexy_settings/printable.rb, line 24
def title(which)
  "##{' ' * 20}#{which.to_s.capitalize} Settings#{' ' * 21}#"
end