Module: Maglev::Page::PublishableConcern

Extended by:
ActiveSupport::Concern
Included in:
Maglev::Page
Defined in:
app/models/maglev/page/publishable_concern.rb

Overview

rubocop:disable Style/ClassAndModuleChildren

Instance Method Summary collapse

Instance Method Details

#apply_published_payloadObject

called when a publishedpage is being previewed



30
31
32
33
34
35
36
# File 'app/models/maglev/page/publishable_concern.rb', line 30

def apply_published_payload
  return if !published? || published_payload.blank?

  published_payload_attributes.each do |attribute|
    send("#{attribute}=", published_payload[attribute])
  end
end

#discard_draft?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/models/maglev/page/publishable_concern.rb', line 25

def discard_draft?
  published? && updated_at > published_at
end

#need_to_be_published?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'app/models/maglev/page/publishable_concern.rb', line 16

def need_to_be_published?
  !published? || updated_at.blank? || updated_at > published_at
end

#published?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'app/models/maglev/page/publishable_concern.rb', line 12

def published?
  published_at.present?
end

#published_and_up_to_date?Boolean

opposite of #need_to_be_published?

Returns:

  • (Boolean)


21
22
23
# File 'app/models/maglev/page/publishable_concern.rb', line 21

def published_and_up_to_date?
  published? && updated_at <= published_at
end

#update_published_payloadObject

called when a page is being published



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/maglev/page/publishable_concern.rb', line 39

def update_published_payload
  # in MySQL, default values for json columns are not supported, so we need to set an empty hash if the value is nil
  self.published_payload ||= {}

  published_payload_attributes.each do |attribute|
    value = send(attribute.to_sym)

    # in MySQL, default values for json columns are not supported, so we need to set an empty hash if the value is nil
    value = {} if attribute.ends_with?('_translations') && value.nil?

    self.published_payload[attribute] = value
  end
end