Class: Feature

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

Constant Summary collapse

FEATURE_ICONS =

Constants

{
  "Dhatu::Product" => "fa-square",
  "Dhatu::Service" => "fa-glass",
  "Dhatu::Project" => "fa-rocket",
  "Dhatu::BlogPost" => "fa-newspaper-o",
  "Dhatu::Price" => "fa-dollar"
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.save_row_data(hsh) ⇒ Object



40
41
42
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
# File 'app/models/feature.rb', line 40

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

Returns:

  • (Boolean)


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

def can_be_deleted?
  true
end

#can_be_edited?Boolean

Permission Methods


Returns:

  • (Boolean)


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

def can_be_edited?
  published? or unpublished?
end

#display_categorisableObject



95
96
97
# File 'app/models/feature.rb', line 95

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

#display_nameObject

  • Return full name

Examples

>>> feature.display_name
=> "Products"


91
92
93
# File 'app/models/feature.rb', line 91

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

#image_configurationObject

Image Configuration




101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'app/models/feature.rb', line 101

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