Class: Feature
- Inherits:
-
Usman::ApplicationRecord
- Object
- ActiveRecord::Base
- Usman::ApplicationRecord
- Feature
- Includes:
- Publishable
- Defined in:
- app/models/feature.rb
Class Method Summary collapse
Instance Method Summary collapse
- #can_be_deleted? ⇒ Boolean
-
#can_be_edited? ⇒ Boolean
Permission Methods ——————.
- #display_categorisable ⇒ Object
-
#display_name ⇒ Object
-
Return full name == Examples >>> feature.display_name => “Products”.
-
-
#image_configuration ⇒ Object
Image Configuration ——————-.
Class Method Details
.save_row_data(hsh) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/models/feature.rb', line 28 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? feature = Feature.find_by_name(hsh[:name].to_s.strip) || Feature.new feature.name = hsh[:name].to_s.strip feature.status = hsh[:status].to_s.strip feature.categorisable = hsh[:categorisable].to_s.strip if feature.valid? begin feature.save! # puts "#{feature.name} saved".green 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 feature: #{feature.name}" details = "Error! #{feature.errors.full_messages.to_sentence}" error_object.errors << { summary: summary, details: details } end return error_object end |
Instance Method Details
#can_be_deleted? ⇒ Boolean
68 69 70 |
# File 'app/models/feature.rb', line 68 def can_be_deleted? true end |
#can_be_edited? ⇒ Boolean
Permission Methods
64 65 66 |
# File 'app/models/feature.rb', line 64 def can_be_edited? published? or unpublished? end |
#display_categorisable ⇒ Object
83 84 85 |
# File 'app/models/feature.rb', line 83 def display_categorisable self.categorisable ? "Yes" : "No" end |
#display_name ⇒ Object
-
Return full name
Examples
>>> feature.display_name
=> "Products"
79 80 81 |
# File 'app/models/feature.rb', line 79 def display_name "#{name.to_s.demodulize.pluralize.titleize}" end |
#image_configuration ⇒ Object
Image Configuration
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/models/feature.rb', line 89 def image_configuration { "Image::FeaturePicture" => { max_upload_limit: 1048576, min_upload_limit: 1024, resolutions: [400, 400], form_upload_image_label: "Upload a new Image", form_title: "Upload an Image (Feature)", form_sub_title: "Please read the instructions below:", form_instructions: [ "the filename should be in .jpg / .jpeg or .png format", "the image resolutions should be <strong>400 x 400 Pixels</strong>", "the file size should be greater than 100 Kb and or lesser than <strong>10 MB</strong>" ] } } end |