Class: Feature

Inherits:
Usman::ApplicationRecord show all
Includes:
Publishable
Defined in:
app/models/feature.rb

Class Method Summary collapse

Instance Method Summary collapse

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
# 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].blank?

  feature = Feature.find_by_name(hsh[:name]) || Feature.new
  feature.name = hsh[:name]
  feature.status = hsh[:status]
  
  if feature.valid?
    begin
      feature.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 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

Returns:

  • (Boolean)


66
67
68
# File 'app/models/feature.rb', line 66

def can_be_deleted?
  true
end

#can_be_edited?Boolean

Permission Methods


Returns:

  • (Boolean)


62
63
64
# File 'app/models/feature.rb', line 62

def can_be_edited?
  published? or unpublished?
end

#display_categorisableObject



81
82
83
# File 'app/models/feature.rb', line 81

def display_categorisable
  self.categorisable ? "Yes" : "No"
end

#display_nameObject

  • Return full name

Examples

>>> feature.display_name
=> "Products"


77
78
79
# File 'app/models/feature.rb', line 77

def display_name
  "#{name.to_s.demodulize.pluralize.titleize}"
end

#image_configurationObject

Image Configuration




87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/feature.rb', line 87

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