Class: Pulitzer::PostTypeVersion::Preview

Inherits:
Object
  • Object
show all
Includes:
StateMachine::Transition
Defined in:
app/services/pulitzer/post_type_version/preview.rb

Instance Method Summary collapse

Constructor Details

#initialize(post_type_version) ⇒ Preview

Returns a new instance of Preview.



8
9
10
11
12
# File 'app/services/pulitzer/post_type_version/preview.rb', line 8

def initialize(post_type_version)
  @post_type_version = post_type_version
  self.object = @post_type_version
  self.errors = ActiveModel::Errors.new(self)
end

Instance Method Details

#previewObject



14
15
16
17
18
19
# File 'app/services/pulitzer/post_type_version/preview.rb', line 14

def preview
  self.validate_transition!
  validate_elements or return false
  update_status
  return true
end

#validate_elementsObject



21
22
23
24
25
26
27
28
# File 'app/services/pulitzer/post_type_version/preview.rb', line 21

def validate_elements
  if @post_type_version.post_type_content_element_types.empty? &&
      @post_type_version.free_form_section_types.empty?
    @post_type_version.errors.add(:base, 'You must set up all the content elements and free form sections before previewing the post type')
    return false
  end
  return true
end