Class: Dhatu::Offer
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Dhatu::Offer
- Includes:
- Featureable, Publishable
- Defined in:
- app/models/dhatu/offer.rb
Class Method Summary collapse
Instance Method Summary collapse
- #can_be_deleted? ⇒ Boolean
-
#can_be_edited? ⇒ Boolean
Permission Methods ——————.
- #display_name ⇒ Object
-
#to_param ⇒ Object
Generic Methods —————.
Class Method Details
.save_row_data(hsh) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/dhatu/offer.rb', line 35 def self.save_row_data(hsh) # Initializing error hash for displaying all errors altogether error_object = Kuppayam::Importer::ErrorHash.new return error_object if hsh[:title].to_s.strip.blank? offer = Dhatu::Offer.find_by_title(hsh[:title].to_s.strip) || Dhatu::Offer.new offer.title = hsh[:title].to_s.strip offer.offer_text = hsh[:offer_text].to_s.strip offer.description = hsh[:description].to_s.strip offer.starts_at = hsh[:starts_at].to_s.strip offer.ends_at = hsh[:ends_at].to_s.strip offer.category = Dhatu::Category.find_by_name(hsh[:category].to_s.strip) offer.status = hsh[:status].to_s.strip || PUBLISHED offer.featured = hsh[:featured].to_s.strip == "true" offer.priority = hsh[:priority].to_s.strip || 1 if offer.valid? begin offer.save! rescue Exception => e summary = "uncaught #{e} exception while handling connection: #{e.}" details = "Stack trace: #{e.backtrace.map {|l| " #{l}\n"}.join}" error_object.errors << { summary: summary, details: details } end else summary = "Error while saving offer: #{offer.title}" details = "Error! #{offer.errors..to_sentence}" error_object.errors << { summary: summary, details: details } end return error_object end |
Instance Method Details
#can_be_deleted? ⇒ Boolean
90 91 92 |
# File 'app/models/dhatu/offer.rb', line 90 def can_be_deleted? status?(:removed) end |
#can_be_edited? ⇒ Boolean
Permission Methods
86 87 88 |
# File 'app/models/dhatu/offer.rb', line 86 def can_be_edited? status?(:published) or status?(:unpublished) end |
#display_name ⇒ Object
79 80 81 |
# File 'app/models/dhatu/offer.rb', line 79 def display_name "#{title_was}" end |
#to_param ⇒ Object
Generic Methods
75 76 77 |
# File 'app/models/dhatu/offer.rb', line 75 def to_param "#{id}-#{title.parameterize[0..32]}" end |