Class: Description
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Description
- Includes:
- Iso639::Validator
- Defined in:
- app/models/description.rb
Overview
Schema Information
Table name: descriptions
id :integer not null, primary key
locale :string default("en")
text :text
status_id :integer not null
image_id :integer not null
metum_id :integer not null
user_id :integer not null
created_at :datetime
updated_at :datetime
license :string default("cc0-1.0")
Indexes
index_descriptions_on_image_id (image_id)
index_descriptions_on_metum_id (metum_id)
index_descriptions_on_status_id (status_id)
index_descriptions_on_user_id (user_id)
Instance Method Summary collapse
- #approved? ⇒ Boolean
- #available_licenses ⇒ Object
- #license_exists ⇒ Object
- #not_approved? ⇒ Boolean
- #patch_image ⇒ Object
- #ready_to_review? ⇒ Boolean
- #siblings ⇒ Object
- #siblings_by(user) ⇒ Object
- #to_s ⇒ Object
- #update_image ⇒ Object
Instance Method Details
#approved? ⇒ Boolean
59 60 61 |
# File 'app/models/description.rb', line 59 def approved? status_id ==2 end |
#available_licenses ⇒ Object
97 98 99 |
# File 'app/models/description.rb', line 97 def available_licenses ["cc0-1.0", "cc-by-4.0", "cc-by-sa-4.0"] end |
#license_exists ⇒ Object
93 94 95 |
# File 'app/models/description.rb', line 93 def license_exists errors.add(:string, "Must exist") unless available_licenses.include?(license) end |
#not_approved? ⇒ Boolean
62 63 64 |
# File 'app/models/description.rb', line 62 def not_approved? status_id ==3 end |
#patch_image ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'app/models/description.rb', line 83 def patch_image s = image.website.get_strategy if s s.patch(image) else Rails.logger.info "No strategy available for this description's image" return true end end |
#ready_to_review? ⇒ Boolean
65 66 67 |
# File 'app/models/description.rb', line 65 def ready_to_review? status_id == 1 end |
#siblings ⇒ Object
69 70 71 |
# File 'app/models/description.rb', line 69 def siblings Description.where(image_id: image_id).where.not(id: id) end |
#siblings_by(user) ⇒ Object
73 74 75 |
# File 'app/models/description.rb', line 73 def siblings_by(user) Description.where(image_id: image_id).where.not(id: id).where(user_id: user.id) end |
#to_s ⇒ Object
55 56 57 |
# File 'app/models/description.rb', line 55 def to_s metum.to_s + " description for " + image.to_s + " by " + user.to_s end |
#update_image ⇒ Object
77 78 79 80 81 |
# File 'app/models/description.rb', line 77 def update_image image.update_status_code image.save return true end |