Class: TravelAdviceEdition

Inherits:
Object
  • Object
show all
Includes:
Attachable, Mongoid::Document, Mongoid::Timestamps, Parted
Defined in:
app/models/travel_advice_edition.rb

Constant Summary collapse

GOVSPEAK_FIELDS =
[:summary]
ALERT_STATUSES =
[
  "avoid_all_but_essential_travel_to_parts",
  "avoid_all_but_essential_travel_to_whole_country",
  "avoid_all_travel_to_parts",
  "avoid_all_travel_to_whole_country",
]

Class Attribute Summary collapse

Instance Method Summary collapse

Methods included from Attachable

asset_api_client, asset_api_client=, included

Methods included from Parted

included, #order_parts, #whole_body

Class Attribute Details

.fields_to_cloneObject

Returns the value of attribute fields_to_clone.



52
53
54
# File 'app/models/travel_advice_edition.rb', line 52

def fields_to_clone
  @fields_to_clone
end

Instance Method Details

#build_action_as(user, action_type, comment = nil) ⇒ Object



106
107
108
# File 'app/models/travel_advice_edition.rb', line 106

def build_action_as(user, action_type, comment = nil)
  actions.build(requester: user, request_type: action_type, comment: comment)
end

#build_cloneObject



97
98
99
100
101
102
103
104
# File 'app/models/travel_advice_edition.rb', line 97

def build_clone
  new_edition = self.class.new
  self.class.fields_to_clone.each do |attr|
    new_edition[attr] = self.read_attribute(attr)
  end
  new_edition.parts = self.parts.map(&:dup)
  new_edition
end

#indexable_contentObject



88
89
90
91
92
93
94
# File 'app/models/travel_advice_edition.rb', line 88

def indexable_content
  strings = [Govspeak::Document.new(self.summary).to_text]
  parts.each do |part|
    strings << part.title << Govspeak::Document.new(part.body).to_text
  end
  strings.join(" ").strip
end

#previous_versionObject



115
116
117
# File 'app/models/travel_advice_edition.rb', line 115

def previous_version
  self.class.where(country_slug: self.country_slug, :version_number.lt => self.version_number).order_by(version_number: :desc).first
end

#publish_as(user) ⇒ Object



110
111
112
113
# File 'app/models/travel_advice_edition.rb', line 110

def publish_as(user)
  comment = self.minor_update ? 'Minor update' : Govspeak::Document.new(self.change_description).to_text
  build_action_as(user, Action::PUBLISH, comment) && publish
end