Class: SourceMonitor::Item
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- SourceMonitor::Item
- Includes:
- Models::UrlNormalizable
- Defined in:
- app/models/source_monitor/item.rb
Class Method Summary collapse
- .ransackable_associations(_auth_object = nil) ⇒ Object
- .ransackable_attributes(_auth_object = nil) ⇒ Object
Instance Method Summary collapse
- #deleted? ⇒ Boolean
-
#ensure_feed_content_record ⇒ Object
Creates an ItemContent record for feed word count computation when one doesn’t exist.
- #restore! ⇒ Object
- #scraped_content=(value) ⇒ Object
- #scraped_html=(value) ⇒ Object
- #soft_delete!(timestamp: Time.current) ⇒ Object
Methods included from Models::UrlNormalizable
Class Method Details
.ransackable_associations(_auth_object = nil) ⇒ Object
52 53 54 |
# File 'app/models/source_monitor/item.rb', line 52 def ransackable_associations(_auth_object = nil) %w[source] end |
.ransackable_attributes(_auth_object = nil) ⇒ Object
48 49 50 |
# File 'app/models/source_monitor/item.rb', line 48 def ransackable_attributes(_auth_object = nil) %w[title summary url published_at created_at scrape_status] end |
Instance Method Details
#deleted? ⇒ Boolean
65 66 67 |
# File 'app/models/source_monitor/item.rb', line 65 def deleted? deleted_at.present? end |
#ensure_feed_content_record ⇒ Object
Creates an ItemContent record for feed word count computation when one doesn’t exist. The before_save callback on ItemContent will compute feed_word_count from item.content.
40 41 42 43 44 45 |
# File 'app/models/source_monitor/item.rb', line 40 def ensure_feed_content_record return if item_content.present? return if content.blank? create_item_content! end |
#restore! ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/models/source_monitor/item.rb', line 85 def restore! return unless deleted? self.class.transaction do update_columns( deleted_at: nil, updated_at: Time.current ) SourceMonitor::Source.increment_counter(:items_count, source_id) if source_id end end |
#scraped_content=(value) ⇒ Object
61 62 63 |
# File 'app/models/source_monitor/item.rb', line 61 def scraped_content=(value) assign_content_attribute(:scraped_content, value) end |
#scraped_html=(value) ⇒ Object
57 58 59 |
# File 'app/models/source_monitor/item.rb', line 57 def scraped_html=(value) assign_content_attribute(:scraped_html, value) end |
#soft_delete!(timestamp: Time.current) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/models/source_monitor/item.rb', line 69 def soft_delete!(timestamp: Time.current) return if deleted? self.class.transaction do = .in_time_zone if .respond_to?(:in_time_zone) ||= Time.current update_columns( deleted_at: , updated_at: ) SourceMonitor::Source.decrement_counter(:items_count, source_id) if source_id end end |