Sha256: 16749bd209f0c2105756eb00820ef8d4cbc90b1249862ab49252d154142c4e23
Contents?: true
Size: 909 Bytes
Versions: 17
Compression:
Stored size: 909 Bytes
Contents
# @abstract subclass and implement {#save!} and {#destroy!} class Zendesk2::Model < Cistern::Model attr_accessor :errors # @abstract override in subclass # @raise [Zendesk2::Error] if unsuccessful def save! raise NotImplementedError end # calls {#save!} and sets {#errors} if unsuccessful and applicable # @return [Zendesk2::Model] self, regardless of success def save save! rescue Zendesk2::Error => exception self.errors = exception.response[:body]["details"].inject({}){|r,(k,v)| r.merge(k => v.map{|e| e["type"] || e["description"]})} rescue nil self end def destroyed? !self.reload end def destroy destroy! rescue Zendesk2::Error false end # re-define Cistern::Attributes#missing_attributes to require non-blank def missing_attributes(args) ([:connection] | args).select{|arg| val = send("#{arg}"); val.nil? || val == "" } end end
Version data entries
17 entries across 17 versions & 1 rubygems