Class: Dhatu::Category
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Dhatu::Category
- Includes:
- Featureable, Publishable
- Defined in:
- app/models/dhatu/category.rb
Class Method Summary collapse
-
.save_row_data(hsh) ⇒ Object
Import Methods.
Instance Method Summary collapse
- #can_be_archived? ⇒ Boolean
- #can_be_deleted? ⇒ Boolean
-
#can_be_edited? ⇒ Boolean
Permission Methods ——————.
- #can_be_published? ⇒ Boolean
- #can_be_removed? ⇒ Boolean
- #can_be_unpublished? ⇒ Boolean
- #default_image_url(size = "medium") ⇒ Object
-
#display_category_type ⇒ Object
def to_param “#id-#0.0..32” end.
-
#display_name ⇒ Object
Other Methods ——————.
-
#set_end_node! ⇒ Object
Callback methods ——————.
- #set_end_node_of_parent ⇒ Object
Class Method Details
.save_row_data(hsh) ⇒ Object
Import Methods
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 85 86 87 88 89 90 91 92 |
# File 'app/models/dhatu/category.rb', line 54 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? category = Dhatu::Category.find_by_name(hsh[:name].to_s.strip) || Dhatu::Category.new category.name = hsh[:name].to_s.strip category.category_type = hsh[:category_type].to_s.strip category.one_liner = hsh[:one_liner].to_s.strip category.description = hsh[:description].to_s.strip parent = Dhatu::Category.find_by_name(hsh[:parent].to_s.strip) category.parent = parent category.top_parent = parent && parent.top_parent ? parent.top_parent : parent category.status = hsh[:status].to_s.strip || PUBLISHED category.priority = hsh[:priority].to_s.strip || 1 # Initializing error hash for displaying all errors altogether error_object = Kuppayam::Importer::ErrorHash.new if category.valid? begin category.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 category: #{category.name}" details = "Error! #{category.errors..to_sentence}" error_object.errors << { summary: summary, details: details } end return error_object end |
Instance Method Details
#can_be_archived? ⇒ Boolean
139 140 141 142 |
# File 'app/models/dhatu/category.rb', line 139 def can_be_archived? return false if end_node == false or self.sub_categories.any? unpublished? or removed? end |
#can_be_deleted? ⇒ Boolean
124 125 126 127 128 |
# File 'app/models/dhatu/category.rb', line 124 def can_be_deleted? return false unless removed? return false if end_node == false or self.sub_categories.any? true end |
#can_be_edited? ⇒ Boolean
Permission Methods
120 121 122 |
# File 'app/models/dhatu/category.rb', line 120 def can_be_edited? published? or unpublished? end |
#can_be_published? ⇒ Boolean
130 131 132 |
# File 'app/models/dhatu/category.rb', line 130 def can_be_published? unpublished? or archived? end |
#can_be_removed? ⇒ Boolean
144 145 146 147 |
# File 'app/models/dhatu/category.rb', line 144 def can_be_removed? return false if end_node == false or self.sub_categories.any? published? or unpublished? end |
#can_be_unpublished? ⇒ Boolean
134 135 136 137 |
# File 'app/models/dhatu/category.rb', line 134 def can_be_unpublished? return false if end_node == false or self.sub_categories.any? published? or removed? end |
#default_image_url(size = "medium") ⇒ Object
113 114 115 |
# File 'app/models/dhatu/category.rb', line 113 def default_image_url(size="medium") "/assets/dhatu/category-#{size}.png" end |
#display_category_type ⇒ Object
def to_param
"#{id}-#{name.parameterize[0..32]}"
end
109 110 111 |
# File 'app/models/dhatu/category.rb', line 109 def display_category_type self.category_type.try(:demodulize).try(:pluralize).try(:titleize) end |
#display_name ⇒ Object
Other Methods
101 102 103 |
# File 'app/models/dhatu/category.rb', line 101 def display_name self.name end |
#set_end_node! ⇒ Object
Callback methods
152 153 154 |
# File 'app/models/dhatu/category.rb', line 152 def set_end_node! self.update_column(:end_node, self.sub_categories.count < 1) end |
#set_end_node_of_parent ⇒ Object
156 157 158 |
# File 'app/models/dhatu/category.rb', line 156 def set_end_node_of_parent self.parent.set_end_node! if self.parent end |