Sha256: e3bd184e12755b30039b3108815b8f9de04f726bcf94ef30315f9289c5dbb5c3
Contents?: true
Size: 1.24 KB
Versions: 28
Compression:
Stored size: 1.24 KB
Contents
module Workarea class Segment include ApplicationDocument include Commentable include Mongoid::Document::Taggable field :name, type: String embeds_many :rules, class_name: 'Workarea::Segment::Rules::Base', inverse_of: :segment validates :name, presence: true validate do |segment| # Don't decorate this if Segment.count >= 15 segment.errors.add(:base, I18n.t('workarea.errors.messages.max_allowed_segments')) end end def self.find_qualifying(visit) all.select { |s| s.qualifies?(visit) } end def self.current Thread.current[:current_segments] || [] end def self.current=(*segments) Thread.current[:current_segments] = Array.wrap(segments).flatten end def self.enabled? !!Thread.current[:enable_segmentation] end def self.enabled Thread.current[:enable_segmentation] = true yield ensure Thread.current[:enable_segmentation] = nil end def self.with_current(*segments) previous = current self.current = segments enabled { yield } ensure self.current = previous end def qualifies?(visit) return false if visit.blank? rules.all? { |r| r.qualifies?(visit) } end end end
Version data entries
28 entries across 28 versions & 1 rubygems