Class: Pulitzer::PostTypeVersion

Inherits:
ApplicationRecord show all
Includes:
ForeignOffice::Broadcaster, StateMachine::Model
Defined in:
app/models/pulitzer/post_type_version.rb

Defined Under Namespace

Classes: Preview, Publish, Retire

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

assoc_name, attrs_name, convert_hash_to_nested

Instance Attribute Details

#finished_processingObject

Returns the value of attribute finished_processing.



20
21
22
# File 'app/models/pulitzer/post_type_version.rb', line 20

def finished_processing
  @finished_processing
end

#processed_element_countObject

Returns the value of attribute processed_element_count.



20
21
22
# File 'app/models/pulitzer/post_type_version.rb', line 20

def processed_element_count
  @processed_element_count
end

Class Method Details

.convert_nested_assoc(json_hash) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/pulitzer/post_type_version.rb', line 45

def self.convert_nested_assoc(json_hash)
  this_array = json_hash.has_key?(attrs_name) ? json_hash[attrs_name] : [json_hash]
  this_array.map!{|ptv_attrs|
    new_attrs = Pulitzer::PostTypeContentElementType.convert_hash_to_nested ptv_attrs
    new_attrs = Pulitzer::FreeFormSectionType.convert_hash_to_nested new_attrs
    new_attrs = Pulitzer::BackgroundStyle.convert_hash_to_nested new_attrs
    new_attrs = Pulitzer::JustificationStyle.convert_hash_to_nested new_attrs
    new_attrs = Pulitzer::SequenceFlowStyle.convert_hash_to_nested new_attrs
    new_attrs = Pulitzer::ArrangementStyle.convert_hash_to_nested new_attrs
  }
  json_hash
end

.export_configObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/pulitzer/post_type_version.rb', line 31

def self.export_config
  {
    except: [:id, :post_type_id],
    include: {
      post_type_content_element_types: Pulitzer::PostTypeContentElementType.export_config,
      free_form_section_types: Pulitzer::FreeFormSectionType.export_config,
      background_styles: Pulitzer::BackgroundStyle.export_config,
      justification_styles: Pulitzer::JustificationStyle.export_config,
      sequence_flow_styles: Pulitzer::SequenceFlowStyle.export_config,
      arrangement_styles: Pulitzer::ArrangementStyle.export_config
    }
  }
end

Instance Method Details

#all_element_typesObject



90
91
92
# File 'app/models/pulitzer/post_type_version.rb', line 90

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

#arity_displayObject



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

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

#full_nameObject



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

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

#has_display?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'app/models/pulitzer/post_type_version.rb', line 78

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

#has_free_form_sections?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'app/models/pulitzer/post_type_version.rb', line 86

def has_free_form_sections?
  free_form_section_types.any?
end

#has_templated_content_elements?Boolean

Returns:

  • (Boolean)


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

def has_templated_content_elements?
  content_element_types.any?
end

#highest_element_sortObject



94
95
96
97
# File 'app/models/pulitzer/post_type_version.rb', line 94

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)


99
100
101
# File 'app/models/pulitzer/post_type_version.rb', line 99

def locked?
  published? || retired?
end

#published_posts_countObject



127
128
129
# File 'app/models/pulitzer/post_type_version.rb', line 127

def published_posts_count
  post_type.published_type_version.posts.count
end

#serializeObject



121
122
123
124
125
# File 'app/models/pulitzer/post_type_version.rb', line 121

def serialize
  self.attributes.merge \
    processed_element_count: self.processed_element_count,
    finished_processing: self.finished_processing
end

#singleton_postObject



66
67
68
# File 'app/models/pulitzer/post_type_version.rb', line 66

def singleton_post
  posts.first
end

#singleton_post?Boolean

Returns:

  • (Boolean)


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

def singleton_post?
  !plural
end

#singular?Boolean

Returns:

  • (Boolean)


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

def singular?
  !plural
end

#state_changeObject



110
111
112
113
114
115
# File 'app/models/pulitzer/post_type_version.rb', line 110

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

#state_change_displayObject



117
118
119
# File 'app/models/pulitzer/post_type_version.rb', line 117

def state_change_display
  state_change.to_s.humanize
end

#status_displayObject



103
104
105
106
107
108
# File 'app/models/pulitzer/post_type_version.rb', line 103

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