class Lux::Api::Response attr_accessor :data attr_accessor :message def meta key, value @meta ||= {} @meta[key.to_s] = value end def error key, data=nil if data @error_hash ||= {} @error_hash[key.to_s] = data data else @errors ||= [] @errors.push key unless @errors.include?(key) key end end def message what @message = what end def errors? (@error_hash || @errors) ? true : false end def render output = {} output[:data] = @data if @data.present? output[:meta] = @meta if @meta.present? output[:message] = @message if @message.present? if errors? output[:error] ||= {} output[:error][:messages] = @errors if @errors output[:error][:hash] = @error_hash if @error_hash end output end alias :to_hash :render end