Class: Pageflow::Entry

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

Overview

rubocop:todo Style/Documentation

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 Translatable

#default_translation?, #mark_as_default_translation, #mark_as_translation_of, #remove_from_translation_group

Methods included from SerializationBlacklist

#serializable_hash

Methods included from EntryPublicationStates

#last_published_with_noindex?, #publication_state, #published?, #published_at, #published_until, #published_with_password_protection?, #published_without_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.



55
56
57
# File 'app/models/pageflow/entry.rb', line 55

def skip_draft_creation
  @skip_draft_creation
end

Class Method Details

.ransackable_associations(_auth_object = nil) ⇒ Object



148
149
150
# File 'app/models/pageflow/entry.rb', line 148

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

.ransackable_attributes(_auth_object = nil) ⇒ Object



144
145
146
# File 'app/models/pageflow/entry.rb', line 144

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

.ransackable_scopes(_auth_object = nil) ⇒ Object



152
153
154
# File 'app/models/pageflow/entry.rb', line 152

def self.ransackable_scopes(_auth_object = nil)
  [:with_publication_state, :published]
end

Instance Method Details

#blacklist_for_serializationObject



156
157
158
# File 'app/models/pageflow/entry.rb', line 156

def blacklist_for_serialization
  [:password_digest, :features_configuration]
end


140
141
142
# File 'app/models/pageflow/entry.rb', line 140

def default_permalink_slug
  title.to_s.parameterize
end

#duplicateObject



128
129
130
# File 'app/models/pageflow/entry.rb', line 128

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

#edit_lockObject



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

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

#entry_templateObject



63
64
65
66
67
# File 'app/models/pageflow/entry.rb', line 63

def entry_template
  @entry_template ||= site.entry_templates.find_or_initialize_by(
    entry_type_name: type_name
  )
end

#entry_typeObject



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

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

#inherited_feature_state(name) ⇒ Object



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

def inherited_feature_state(name)
  .feature_state(name)
end

#publish(options = {}) ⇒ Object

rubocop:todo Metrics/AbcSize



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/models/pageflow/entry.rb', line 81

def publish(options = {}) # rubocop:todo Metrics/AbcSize
  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]
      revision.noindex = !!options[:noindex]
    end
  end
end

#restore(options) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/models/pageflow/entry.rb', line 110

def restore(options)
  transaction do
    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
      revision.noindex = nil
    end
  end
end

#should_generate_new_friendly_id?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'app/models/pageflow/entry.rb', line 132

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

#slug_candidatesObject



136
137
138
# File 'app/models/pageflow/entry.rb', line 136

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

#snapshot(options) ⇒ Object



100
101
102
103
104
105
106
107
108
# File 'app/models/pageflow/entry.rb', line 100

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