class SpudBannerSet < ActiveRecord::Base has_many :banners, ->{ order('sort_order asc') }, :class_name => 'SpudBanner', :dependent => :destroy, :inverse_of => :owner validates_presence_of :name validates_uniqueness_of :name validates_numericality_of :width, :height acts_as_tb_liquid_tag :spud_banner_set, :name after_update :check_for_dimension_change def self.find_by_identifier(identifier) if identifier.class == String banner_set = SpudBannerSet.find_by_name(identifier) elsif identifier.class == Symbol banner_set = SpudBannerSet.find_by_name(identifier.to_s.titleize) else banner_set = SpudBannerSet.find(identifier) end return banner_set end def reprocess_banners! self.banners.each do |banner| banner.banner.reprocess! end end def set_name return name end private def check_for_dimension_change if self.height_changed? || self.width_changed? || self.cropped_changed? self.reprocess_banners! end end end