Class: Pageflow::Entry

Inherits:
ApplicationRecord show all
Extended by:
FriendlyId
Includes:
EntryPublicationStates, FeatureTarget, Permalinkable, SerializationBlacklist
Defined in:
app/models/pageflow/entry.rb

Defined Under Namespace

Classes: PasswordMissingError

Constant Summary

Constants included from FeatureTarget

FeatureTarget::STATE_MAPPING

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializationBlacklist

#serializable_hash

Methods included from EntryPublicationStates

#publication_state, #published?, #published_at, #published_until, #published_with_password_protection?

Methods included from FeatureTarget

#enabled_feature_names, #feature_state, #feature_states=, #features_configuration, #own_feature_state

Instance Attribute Details

#skip_draft_creationObject

Returns the value of attribute skip_draft_creation.



51
52
53
# File 'app/models/pageflow/entry.rb', line 51

def skip_draft_creation
  @skip_draft_creation
end

Class Method Details

.ransackable_associations(_auth_object) ⇒ Object



138
139
140
# File 'app/models/pageflow/entry.rb', line 138

def self.ransackable_associations(_auth_object)
  %w[account published_revision]
end

.ransackable_attributes(_auth_object) ⇒ Object



134
135
136
# File 'app/models/pageflow/entry.rb', line 134

def self.ransackable_attributes(_auth_object)
  %w[title type_name created_at edited_at first_published_at]
end

.ransackable_scopes(_) ⇒ Object



142
143
144
# File 'app/models/pageflow/entry.rb', line 142

def self.ransackable_scopes(_)
  [:with_publication_state, :published]
end

Instance Method Details

#blacklist_for_serializationObject



146
147
148
# File 'app/models/pageflow/entry.rb', line 146

def blacklist_for_serialization
  [:password_digest, :features_configuration]
end


130
131
132
# File 'app/models/pageflow/entry.rb', line 130

def default_permalink_slug
  title.to_s.parameterize
end

#duplicateObject



118
119
120
# File 'app/models/pageflow/entry.rb', line 118

def duplicate
  EntryDuplicate.of(self).create!
end

#edit_lockObject



70
71
72
# File 'app/models/pageflow/entry.rb', line 70

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

#entry_templateObject



59
60
61
62
63
64
# File 'app/models/pageflow/entry.rb', line 59

def entry_template
  @entry_template ||= EntryTemplate.find_or_initialize_by(
    account_id: .id,
    entry_type_name: type_name
  )
end

#entry_typeObject



66
67
68
# File 'app/models/pageflow/entry.rb', line 66

def entry_type
  Pageflow.config.entry_types.find_by_name!(type_name)
end

#inherited_feature_state(name) ⇒ Object



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

def inherited_feature_state(name)
  .feature_state(name)
end

#publish(options = {}) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/pageflow/entry.rb', line 78

def publish(options = {})
  ActiveRecord::Base.transaction do
    self.first_published_at ||= Time.now
    update_password!(options.slice(:password, :password_protected))

    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]
      revision.password_protected = options[:password_protected]
    end
  end
end

#restore(options) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/pageflow/entry.rb', line 104

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.snapshot_type = nil
    revision.published_at = nil
    revision.published_until = nil
    revision.password_protected = nil
  end
end

#should_generate_new_friendly_id?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'app/models/pageflow/entry.rb', line 122

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

#slug_candidatesObject



126
127
128
# File 'app/models/pageflow/entry.rb', line 126

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

#snapshot(options) ⇒ Object



96
97
98
99
100
101
102
# File 'app/models/pageflow/entry.rb', line 96

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