Class: Product
- Inherits:
-
Vyapari::ApplicationRecord
- Object
- ActiveRecord::Base
- Vyapari::ApplicationRecord
- Product
- Defined in:
- app/models/product.rb
Constant Summary collapse
- PUBLISHED =
Constants
"published"
- UNPUBLISHED =
"unpublished"
- REMOVED =
"removed"
- STATUS_HASH =
{"Published" => PUBLISHED, "Unpublished" => UNPUBLISHED, "Removed" => REMOVED}
- STATUS_HASH_REVERSE =
{PUBLISHED => "Published", UNPUBLISHED => "Unpublished", REMOVED => "Removed"}
- FEATURED_HASH =
{"Featured" => true, "Non Featured" => false}
- FEATURED_HASH_REVERSE =
{true => "Featured", false => "Non Featured"}
Instance Method Summary collapse
-
#can_be_deleted? ⇒ Boolean
TODO.
- #default_image_url(size = "medium") ⇒ Object
-
#publish! ⇒ Object
change the status to :published Return the status == Examples >>> brand.publish! => “published”.
-
#published? ⇒ Boolean
-
Return true if the brand is published, else false.
-
-
#remove! ⇒ Object
change the status to :removed Return the status == Examples >>> brand.remove! => “removed”.
-
#removed? ⇒ Boolean
-
Return true if the brand is removed, else false.
-
-
#unpublish! ⇒ Object
change the status to :unpublished Return the status == Examples >>> brand.unpublish! => “unpublished”.
-
#unpublished? ⇒ Boolean
-
Return true if the brand is unpublished, else false.
-
Instance Method Details
#can_be_deleted? ⇒ Boolean
TODO
109 110 111 112 113 114 115 116 117 |
# File 'app/models/product.rb', line 109 def can_be_deleted? #if self.jobs.any? # self.errors.add(:base, DELETE_MESSAGE) # return false #else # return true #end return true end |
#default_image_url(size = "medium") ⇒ Object
119 120 121 |
# File 'app/models/product.rb', line 119 def default_image_url(size="medium") "/assets/defaults/product-#{size}.png" end |
#publish! ⇒ Object
change the status to :published Return the status
Examples
>>> brand.publish!
=> "published"
70 71 72 |
# File 'app/models/product.rb', line 70 def publish! self.update_attribute(:status, PUBLISHED) end |
#published? ⇒ Boolean
-
Return true if the brand is published, else false.
Examples
>>> brand.published?
=> true
61 62 63 |
# File 'app/models/product.rb', line 61 def published? (status == PUBLISHED) end |
#remove! ⇒ Object
change the status to :removed Return the status
Examples
>>> brand.remove!
=> "removed"
104 105 106 |
# File 'app/models/product.rb', line 104 def remove! self.update_attributes(status: REMOVED, featured: false) end |
#removed? ⇒ Boolean
-
Return true if the brand is removed, else false.
Examples
>>> brand.removed?
=> true
95 96 97 |
# File 'app/models/product.rb', line 95 def removed? (status == REMOVED) end |
#unpublish! ⇒ Object
change the status to :unpublished Return the status
Examples
>>> brand.unpublish!
=> "unpublished"
87 88 89 |
# File 'app/models/product.rb', line 87 def unpublish! self.update_attributes(status: UNPUBLISHED, featured: false) end |
#unpublished? ⇒ Boolean
-
Return true if the brand is unpublished, else false.
Examples
>>> brand.unpublished?
=> true
78 79 80 |
# File 'app/models/product.rb', line 78 def unpublished? (status == UNPUBLISHED) end |