Class: Pageflow::Entry

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Defined in:
app/models/pageflow/entry.rb

Instance Method Summary collapse

Instance Method Details

#edit_lockObject


38
39
40
# File 'app/models/pageflow/entry.rb', line 38

def edit_lock
  super || EditLock::Null.new(self)
end

#publish(options = {}) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
# File 'app/models/pageflow/entry.rb', line 42

def publish(options = {})
  revisions.depublish_all
  association(:published_revision).reset

  draft.copy do |revision|
    revision.creator = options[:creator]
    revision.frozen_at = Time.now
    revision.published_at = Time.now
    revision.published_until = options[:published_until]
  end
end

#published?Boolean


74
75
76
# File 'app/models/pageflow/entry.rb', line 74

def published?
  published_revision.present?
end

#published_untilObject


78
79
80
# File 'app/models/pageflow/entry.rb', line 78

def published_until
  published? ? published_revision.published_until : nil
end

#restore(options) ⇒ Object


62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/pageflow/entry.rb', line 62

def restore(options)
  restored_revision = options.fetch(:revision)
  draft.update!(:frozen_at => Time.now, :creator => options[:creator], :snapshot_type => 'before_restore')

  restored_revision.copy do |revision|
    revision.restored_from = restored_revision
    revision.frozen_at = nil
    revision.published_at = nil
    revision.published_until = nil
  end
end

#should_generate_new_friendly_id?Boolean


82
83
84
# File 'app/models/pageflow/entry.rb', line 82

def should_generate_new_friendly_id?
  slug.blank? || title_changed?
end

#slug_candidatesObject


86
87
88
# File 'app/models/pageflow/entry.rb', line 86

def slug_candidates
  [:title, [:title, :id]]
end

#snapshot(options) ⇒ Object


54
55
56
57
58
59
60
# File 'app/models/pageflow/entry.rb', line 54

def snapshot(options)
  draft.copy do |revision|
    revision.creator = options[:creator]
    revision.frozen_at = Time.now
    revision.snapshot_type = options.fetch(:type, 'auto')
  end
end