Sha256: 4240bf86c1c3f8203fcdc17a463edd6fd2bf4525daa88b29576cbdf7ed206773

Contents?: true

Size: 913 Bytes

Versions: 18

Compression:

Stored size: 913 Bytes

Contents

class Zendesk2::Client::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)
    ([:service] | args).select{|arg| val = send("#{arg}"); val.nil? || val == "" }
  end

  def update!(attributes)
    merge_attributes(attributes)
    save!
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
zendesk2-1.7.1 lib/zendesk2/client/model.rb
zendesk2-1.7.0 lib/zendesk2/client/model.rb
zendesk2-1.6.1 lib/zendesk2/client/model.rb
zendesk2-1.5.17 lib/zendesk2/client/model.rb
zendesk2-1.5.16 lib/zendesk2/client/model.rb
zendesk2-1.5.15 lib/zendesk2/client/model.rb
zendesk2-1.5.14 lib/zendesk2/client/model.rb
zendesk2-1.5.13 lib/zendesk2/client/model.rb
zendesk2-1.5.12 lib/zendesk2/client/model.rb
zendesk2-1.5.11 lib/zendesk2/client/model.rb
zendesk2-1.5.10 lib/zendesk2/client/model.rb
zendesk2-1.5.9 lib/zendesk2/client/model.rb
zendesk2-1.5.8 lib/zendesk2/client/model.rb
zendesk2-1.5.7 lib/zendesk2/client/model.rb
zendesk2-1.5.6 lib/zendesk2/client/model.rb
zendesk2-1.5.5 lib/zendesk2/client/model.rb
zendesk2-1.5.4 lib/zendesk2/client/model.rb
zendesk2-1.5.3 lib/zendesk2/client/model.rb