Class: Dhatu::Service

Inherits:
ApplicationRecord show all
Includes:
Featureable, Publishable
Defined in:
app/models/dhatu/service.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.save_row_data(hsh) ⇒ Object



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
68
69
70
71
# File 'app/models/dhatu/service.rb', line 39

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[:name].to_s.strip.blank?

  service = Dhatu::Service.find_by_name(hsh[:name].to_s.strip) || Dhatu::Service.new
  service.name = hsh[:name].to_s.strip
  service.short_description = hsh[:short_description].to_s.strip
  service.generate_permalink
  service.description = hsh[:description].to_s.strip
  service.price = hsh[:price].to_s.strip
  service.duration = hsh[:duration].to_s.strip
  service.category = Dhatu::Category.find_by_name(hsh[:category].to_s.strip)
  service.status = hsh[:status].to_s.strip.blank? ? PUBLISHED : hsh[:status].to_s.strip
  service.featured = hsh[:featured].to_s.strip || true
  service.priority = hsh[:priority].to_s.strip || 1

  if service.valid?
    begin
      service.save!
    rescue Exception => e
      summary = "uncaught #{e} exception while handling connection: #{e.message}"
      details = "Stack trace: #{e.backtrace.map {|l| "  #{l}\n"}.join}"
      error_object.errors << { summary: summary, details: details }        
    end
  else
    summary = "Error while saving service: #{service.name}"
    details = "Error! #{service.errors.full_messages.to_sentence}"
    error_object.errors << { summary: summary, details: details }
  end
  return error_object
end

Instance Method Details

#can_be_deleted?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'app/models/dhatu/service.rb', line 98

def can_be_deleted?
  status?(:removed)
end

#can_be_edited?Boolean

Permission Methods


Returns:

  • (Boolean)


94
95
96
# File 'app/models/dhatu/service.rb', line 94

def can_be_edited?
  status?(:published) or status?(:unpublished)
end

#display_nameObject



87
88
89
# File 'app/models/dhatu/service.rb', line 87

def display_name
  "#{name_was}"
end


83
84
85
# File 'app/models/dhatu/service.rb', line 83

def generate_permalink
  self.permalink = self.name.parameterize[0..32]
end

#to_paramObject

Generic Methods




79
80
81
# File 'app/models/dhatu/service.rb', line 79

def to_param
  "#{id}-#{name.parameterize[0..32]}"
end