Class: Pulitzer::PostTypeVersion

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
StateMachine::Model
Defined in:
app/models/pulitzer/post_type_version.rb

Defined Under Namespace

Classes: Preview, Publish, Retire

Instance Method Summary collapse

Instance Method Details

#all_element_typesObject



54
55
56
# File 'app/models/pulitzer/post_type_version.rb', line 54

def all_element_types
  (post_type_content_element_types.to_a + free_form_section_types.to_a)
end

#arity_displayObject



38
39
40
# File 'app/models/pulitzer/post_type_version.rb', line 38

def arity_display
  plural? ? 'Many Posts' : 'Single Post'
end

#full_nameObject



22
23
24
# File 'app/models/pulitzer/post_type_version.rb', line 22

def full_name
  "\"#{name}\" v#{version_number}"
end

#has_display?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/pulitzer/post_type_version.rb', line 42

def has_display?
  background_styles.any? || justification_styles.any? || sequence_flow_styles.any? || arrangement_styles.any?
end

#has_free_form_sections?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'app/models/pulitzer/post_type_version.rb', line 50

def has_free_form_sections?
  free_form_section_types.any?
end

#has_templated_content_elements?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'app/models/pulitzer/post_type_version.rb', line 46

def has_templated_content_elements?
  content_element_types.any?
end

#highest_element_sortObject



58
59
60
61
# File 'app/models/pulitzer/post_type_version.rb', line 58

def highest_element_sort
  last_element = all_element_types.max_by{ |e| e.sort_order || 0}
  last_element&.sort_order || 0
end

#locked?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'app/models/pulitzer/post_type_version.rb', line 63

def locked?
  published? || retired?
end

#singleton_postObject



30
31
32
# File 'app/models/pulitzer/post_type_version.rb', line 30

def singleton_post
  posts.first
end

#singleton_post?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/pulitzer/post_type_version.rb', line 34

def singleton_post?
  !plural
end

#singular?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/models/pulitzer/post_type_version.rb', line 26

def singular?
  !plural
end

#state_changeObject



74
75
76
77
78
79
# File 'app/models/pulitzer/post_type_version.rb', line 74

def state_change
  {'incomplete' => :preview,
    'preview' => :publish,
    'published' => :retire,
    'retired' => :publish}[status]
end

#state_change_displayObject



81
82
83
# File 'app/models/pulitzer/post_type_version.rb', line 81

def state_change_display
  state_change.to_s.humanize
end

#status_displayObject



67
68
69
70
71
72
# File 'app/models/pulitzer/post_type_version.rb', line 67

def status_display
  {'incomplete' => 'Not Ready',
    'preview' => 'Previewing',
    'published' => 'Published',
    'retired' => 'Retired'}[status]
end