Class: Dhatu::Section

Inherits:
ApplicationRecord show all
Includes:
Publishable
Defined in:
app/models/dhatu/section.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.save_row_data(hsh) ⇒ Object



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
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/models/dhatu/section.rb', line 43

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

  section = Dhatu::Section.where("code = ?", hsh[:code].to_s.strip).first || Dhatu::Section.new

  section.name = hsh[:name].to_s.strip
  section.code = hsh[:code].to_s.strip

  section.title = hsh[:title].to_s.strip
  section.sub_title = hsh[:sub_title].to_s.strip

  section.short_description = hsh[:short_description].to_s.strip
  section.long_description = hsh[:long_description].to_s.strip

  section.button_one_text = hsh[:button_one_text].to_s.strip
  section.button_two_text = hsh[:button_two_text].to_s.strip
  section.button_one_link = hsh[:button_one_link].to_s.strip
  section.button_two_link = hsh[:button_two_link].to_s.strip

  section.page = Dhatu::Page.where("code = ?", hsh[:page].to_s.strip).first

  section.status = hsh[:status].to_s.strip || PUBLISHED
  section.priority = hsh[:priority].to_s.strip || 1

  if section.valid?
    begin
      section.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 section: #{section.title}"
    details = "Error! #{section.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)


107
108
109
# File 'app/models/dhatu/section.rb', line 107

def can_be_deleted?
  status?(:removed)
end

#can_be_edited?Boolean

Permission Methods


Returns:

  • (Boolean)


103
104
105
# File 'app/models/dhatu/section.rb', line 103

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

#display_nameObject



96
97
98
# File 'app/models/dhatu/section.rb', line 96

def display_name
  "#{name_was}"
end

#to_paramObject

Generic Methods




92
93
94
# File 'app/models/dhatu/section.rb', line 92

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