Class: Feature
- Inherits:
-
Usman::ApplicationRecord
- Object
- ActiveRecord::Base
- Usman::ApplicationRecord
- Feature
- Extended by:
- Usman::ImportErrorHandler
- Defined in:
- app/models/feature.rb
Constant Summary collapse
- UNPUBLISHED =
Constants
"unpublished"- PUBLISHED =
"published"- DISABLED =
"disabled"- STATUS =
{ UNPUBLISHED => "Un-Published", PUBLISHED => "Published", DISABLED => "Disabled" }
- STATUS_REVERSE =
{ "Un-Published" => UNPUBLISHED, "Published" => PUBLISHED, "Disabled" => DISABLED }
Class Method Summary collapse
Instance Method Summary collapse
- #can_be_destroyed? ⇒ Boolean
-
#disabled? ⇒ Boolean
-
Return true if the user is disabled, else false.
-
-
#display_name ⇒ Object
-
Return full name == Examples >>> feature.display_name => “Products”.
-
-
#publish! ⇒ Object
change the status to :published Return the status == Examples >>> feature.publish! => “published”.
-
#published? ⇒ Boolean
-
Return true if the user is not published, else false.
-
-
#suspend! ⇒ Object
change the status to :suspended Return the status == Examples >>> feature.suspend! => “suspended”.
-
#unpublish! ⇒ Object
change the status to :unpublished Return the status == Examples >>> feature.unpublish! => “unpublished”.
-
#unpublished? ⇒ Boolean
-
Return true if the user is unpublished, else false.
-
Methods included from Usman::ImportErrorHandler
Class Method Details
.save_row_data(row, base_path) ⇒ Object
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 85 86 87 88 89 90 91 92 93 |
# File 'app/models/feature.rb', line 50 def self.save_row_data(row, base_path) image_base_path = base_path + "images/" row.headers.each{ |cell| row[cell] = row[cell].to_s.strip } return if row[:name].blank? feature = Feature.find_by_name(row[:name]) || Feature.new feature.name = row[:name] feature.status = Feature::UNPUBLISHED # Initializing error hash for displaying all errors altogether error_object = Usman::ErrorHash.new ## Adding a profile picture begin image_path = image_base_path + "features/#{feature.name.parameterize}.png" image_path = image_base_path + "features/#{feature.name.parameterize}}.jpg" unless File.exists?(image_path) if File.exists?(image_path) feature.build_feature_image feature.feature_image.image = File.open(image_path) else summary = "Feature Image not found for feature: #{feature.name}" details = "#{image_path}/png doesn't exists" error_object.warnings << { summary: summary, details: details } end rescue => e summary = "Error during processing: #{$!}" details = "Feature: #{feature.name}, Image Path: #{image_path}" stack_trace = "Backtrace:\n\t#{e.backtrace.join("\n\t")}" error_object.errors << { summary: summary, details: details, stack_trace: stack_trace } end if feature.feature_image.blank? if feature.valid? && (feature.feature_image.blank? || feature.feature_image.valid?) feature.save! else summary = "Error while saving feature: #{feature.name}" details = "Error! #{feature.errors..to_sentence}" details << ", #{feature.feature_image.errors..to_sentence}" if feature.feature_image error_object.errors << { summary: summary, details: details } end return error_object end |
Instance Method Details
#can_be_destroyed? ⇒ Boolean
154 155 156 |
# File 'app/models/feature.rb', line 154 def can_be_destroyed? return true end |
#disabled? ⇒ Boolean
-
Return true if the user is disabled, else false.
Examples
>>> feature.disabled?
=> true
123 124 125 |
# File 'app/models/feature.rb', line 123 def disabled? (status == DISABLED) end |
#display_name ⇒ Object
-
Return full name
Examples
>>> feature.display_name
=> "Products"
99 100 101 |
# File 'app/models/feature.rb', line 99 def display_name "#{name}" end |
#publish! ⇒ Object
change the status to :published Return the status
Examples
>>> feature.publish!
=> "published"
141 142 143 |
# File 'app/models/feature.rb', line 141 def publish! self.update_attribute(:status, PUBLISHED) end |
#published? ⇒ Boolean
-
Return true if the user is not published, else false.
Examples
>>> feature.published?
=> true
107 108 109 |
# File 'app/models/feature.rb', line 107 def published? (status == PUBLISHED) end |
#suspend! ⇒ Object
change the status to :suspended Return the status
Examples
>>> feature.suspend!
=> "suspended"
150 151 152 |
# File 'app/models/feature.rb', line 150 def suspend! self.update_attribute(:status, DISABLED) end |
#unpublish! ⇒ Object
change the status to :unpublished Return the status
Examples
>>> feature.unpublish!
=> "unpublished"
132 133 134 |
# File 'app/models/feature.rb', line 132 def unpublish! self.update_attribute(:status, UNPUBLISHED) end |
#unpublished? ⇒ Boolean
-
Return true if the user is unpublished, else false.
Examples
>>> feature.unpublished?
=> true
115 116 117 |
# File 'app/models/feature.rb', line 115 def unpublished? (status == UNPUBLISHED) end |