class Dhatu::MetaTag < Dhatu::ApplicationRecord # Constants META_TYPES = ["Default", "Open Graph", "Twitter", "Facebook", "Other"] # Set Table Name self.table_name = "meta_tags" # Including the State Machine Methods include Publishable # Validations validates :meta_type, presence: true, length: {minimum: 3, maximum: 16}, allow_blank: false validates :meta_key, presence: true, length: {minimum: 1, maximum: 128}, allow_blank: false validates :meta_value, presence: true, length: {minimum: 1, maximum: 1064}, allow_blank: false # Associations belongs_to :meta_taggable, :polymorphic => true # ------------------ # Class Methods # ------------------ scope :search, lambda { |query| where("LOWER(meta_type) LIKE LOWER('%#{query}%') OR LOWER(meta_key) LIKE LOWER('%#{query}%') OR LOWER(meta_value) LIKE LOWER('%#{query}%')") } # ------------------ # Instance Methods # ------------------ # Generic Methods # --------------- def display_name "#{self.meta_type_was} - #{self.meta_key_was}" end # Permission Methods # ------------------ def can_be_edited? status?(:published) or status?(:unpublished) end def can_be_deleted? status?(:removed) end end