Class: Pulitzer::ContentElement

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/pulitzer/content_element.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ensure_uniqueObject

Returns the value of attribute ensure_unique.



13
14
15
# File 'app/models/pulitzer/content_element.rb', line 13

def ensure_unique
  @ensure_unique
end

#version_unavailableObject

Returns the value of attribute version_unavailable.



13
14
15
# File 'app/models/pulitzer/content_element.rb', line 13

def version_unavailable
  @version_unavailable
end

Instance Method Details

#clone_image(clone_attrs) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/models/pulitzer/content_element.rb', line 63

def clone_image(clone_attrs)
  clone_attrs.delete 'image'
  my_clone = Pulitzer::ContentElement.new(clone_attrs)
  if image.file && image.file.exists?
    my_clone.remote_image_url = image.url
    # If there is an error getting the image, don't bail out,
    # create the content element clone without the image so the user can reupload later
    if !my_clone.valid?
      if my_clone.errors.get(:image)
        my_clone = Pulitzer::ContentElement.new(clone_attrs)
      end
    end
  end
  my_clone.save!
  my_clone
end

#clone_meObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/pulitzer/content_element.rb', line 48

def clone_me
  clone_attrs = self.attributes.dup
  clone_attrs.delete 'id'
  clone_attrs.delete 'version_id'

  type_clone_method = 'clone_' + type.to_s

  if respond_to? type_clone_method
    my_clone = send type_clone_method, clone_attrs
  else
    my_clone = Pulitzer::ContentElement.create!(clone_attrs)
  end
  my_clone
end

#empty_body?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/models/pulitzer/content_element.rb', line 44

def empty_body?
  image_type? ? !image? : body.blank?
end

#htmlObject



40
41
42
# File 'app/models/pulitzer/content_element.rb', line 40

def html
  body.blank? ? "" : body.html_safe
end

def reprocess_versions!

self.photo.recreate_versions!
self.broadcast_change

end



34
35
36
37
38
# File 'app/models/pulitzer/content_element.rb', line 34

def video_link
  if video_type? && !body.nil?
    vimeo_video(body) || youtube_video(body)
  end
end