class Porch::HumanError

Attributes

errors[R]
seperator[RW]

Public Class Methods

new(errors, seperator=", ") click to toggle source
# File lib/porch/human_error.rb, line 6
def initialize(errors, seperator=", ")
  @errors = errors
  @seperator = seperator
end

Public Instance Methods

message() click to toggle source
# File lib/porch/human_error.rb, line 11
def message
  collect_messages(errors).join(seperator)
end

Private Instance Methods

append_descriptions(attribute, descriptions) click to toggle source
# File lib/porch/human_error.rb, line 31
def append_descriptions(attribute, descriptions)
  descriptions.collect { |description| "#{attribute} #{description}" }.join(seperator)
end
append_message(attribute_prefix, attribute, descriptions) click to toggle source
# File lib/porch/human_error.rb, line 27
def append_message(attribute_prefix, attribute, descriptions)
  append_descriptions(humanize(attribute_prefix, attribute), descriptions)
end
capitalize(string) click to toggle source
# File lib/porch/human_error.rb, line 39
def capitalize(string)
  CoreExt::String.new(string).capitalize
end
collect_messages(error_hash, attribute_prefix=nil) click to toggle source
# File lib/porch/human_error.rb, line 17
def collect_messages(error_hash, attribute_prefix=nil)
  error_hash.collect do |attribute, descriptions|
    if descriptions.is_a? Hash
      collect_messages descriptions, attribute
    else
      append_message attribute_prefix, attribute, descriptions
    end
  end
end
humanize(attribute_prefix, attribute) click to toggle source
# File lib/porch/human_error.rb, line 35
def humanize(attribute_prefix, attribute)
  capitalize("#{attribute_prefix} #{attribute}".lstrip)
end