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

Version Path
zendesk2-1.4.2 lib/zendesk2/model.rb
zendesk2-1.4.1 lib/zendesk2/model.rb
zendesk2-1.4.0 lib/zendesk2/model.rb
zendesk2-1.3.3 lib/zendesk2/model.rb
zendesk2-1.3.2 lib/zendesk2/model.rb
zendesk2-1.3.1 lib/zendesk2/model.rb
zendesk2-1.3.0 lib/zendesk2/model.rb
zendesk2-1.2.10 lib/zendesk2/model.rb
zendesk2-1.2.9 lib/zendesk2/model.rb
zendesk2-1.2.7 lib/zendesk2/model.rb
zendesk2-1.2.6 lib/zendesk2/model.rb
zendesk2-1.2.5 lib/zendesk2/model.rb
zendesk2-1.2.4 lib/zendesk2/model.rb
zendesk2-1.2.3 lib/zendesk2/model.rb
zendesk2-1.2.2 lib/zendesk2/model.rb
zendesk2-1.2.1 lib/zendesk2/model.rb
zendesk2-1.2.0 lib/zendesk2/model.rb