Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 29 lines (23 sloc) 0.67 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
class Response

  attr_accessor :success, :data
  attr_reader :errors
  
  def initialize data = []
    @data = []
    @data << data
    @data.flatten!
    @errors = ActiveModel::Errors.new self
  end

  def to_yaml
    {success: @success, data: @data, errors: @errors.full_messages}.to_yaml
  end

  def self.human_attribute_name attr, options={}
    attr
  end

  def merge_errors other_errors, options={}
    other_object_string = " of the #{options[:object_name].downcase}" if options[:object_name] and !options[:object_name].empty?
    other_errors.each do |key, error|
      @errors.add :"#{key.capitalize}#{other_object_string}", error
    end
    self
  end
end
Something went wrong with that request. Please try again.