Module: DraftPunk::Model::InstanceInterrogators

Defined in:
lib/activerecord/activerecord_instance_methods.rb

Instance Method Summary collapse

Instance Method Details

#has_draft?Boolean

Returns whether the current ActiveRecord object has a draft version.

Returns:

  • (Boolean)

    whether the current ActiveRecord object has a draft version

Raises:



200
201
202
203
# File 'lib/activerecord/activerecord_instance_methods.rb', line 200

def has_draft?
  raise DraftPunk::ApprovedVersionIdError unless respond_to?(:approved_version_id)
  draft.present? && !publishing_draft?
end

#is_draft?Boolean

Returns whether the current ActiveRecord object is a draft.

Returns:

  • (Boolean)

    whether the current ActiveRecord object is a draft

Raises:



194
195
196
197
# File 'lib/activerecord/activerecord_instance_methods.rb', line 194

def is_draft?
  raise DraftPunk::ApprovedVersionIdError unless respond_to?("approved_version_id")
  approved_version_id.present?
end

#is_previous_version?Boolean

Returns whether the current ActiveRecord object is a previously-approved version of another instance of this class.

Returns:

  • (Boolean)

    whether the current ActiveRecord object is a previously-approved version of another instance of this class



207
208
209
210
211
# File 'lib/activerecord/activerecord_instance_methods.rb', line 207

def is_previous_version?
  tracks_approved_version_history? &&
  !is_draft? &&
  current_approved_version_id.present?
end