Class: Pageflow::Revision

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/pageflow/revision.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.depublish_allObject


99
100
101
# File 'app/models/pageflow/revision.rb', line 99

def self.depublish_all
  published.update_all(:published_until => Time.now)
end

Instance Method Details

#copy {|revision| ... } ⇒ Object

Yields:

  • (revision)

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/models/pageflow/revision.rb', line 73

def copy(&block)
  revision = dup
  yield(revision) if block_given?

  widgets.each do |widget|
    widget.copy_to(revision)
  end

  chapters.each do |chapter|
    chapter.copy_to(revision)
  end

  file_usages.each do |file_usage|
    file_usage.copy_to(revision)
  end

  Pageflow.config.revision_components.each do |model|
    model.all_for_revision(self).each do |record|
      record.copy_to(revision)
    end
  end

  revision.save!
  revision
end

#created_withObject


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

def created_with
  if published_at
    :publish
  elsif snapshot_type == 'auto'
    :auto
  elsif snapshot_type == 'user'
    :user
  else
    :restore
  end
end

#creatorObject


44
45
46
# File 'app/models/pageflow/revision.rb', line 44

def creator
  super || NullUser.new
end

#files(model) ⇒ Object


37
38
39
40
41
42
# File 'app/models/pageflow/revision.rb', line 37

def files(model)
  model
    .select("#{model.table_name}.*, pageflow_file_usages.id AS usage_id")
    .joins(:usages)
    .where(pageflow_file_usages: {revision_id: id})
end

#frozen?Boolean


57
58
59
# File 'app/models/pageflow/revision.rb', line 57

def frozen?
  frozen_at.present?
end

#pagesObject


48
49
50
# File 'app/models/pageflow/revision.rb', line 48

def pages
  super.tap { |p| p.first.is_first = true if p.present? }
end

#published?Boolean


52
53
54
55
# File 'app/models/pageflow/revision.rb', line 52

def published?
  (published_at.present? && Time.now >= published_at) &&
    (published_until.blank? || Time.now < published_until)
end