Module: Workarea::Segmentable

Extended by:
ActiveSupport::Concern
Included in:
Releasable
Defined in:
app/models/workarea/segmentable.rb

Instance Method Summary collapse

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/workarea/segmentable.rb', line 40

def active?
  default = super
  return default unless Segment.enabled?
  return false unless default

  if active_segment_ids.blank?
    true
  else
    allowed_ids = active_segment_ids.map(&:to_s)
    Segment.current.any? { |s| allowed_ids.include?(s.id.to_s) }
  end
end

#active_segment_ids_with_childrenObject



61
62
63
64
65
66
67
68
# File 'app/models/workarea/segmentable.rb', line 61

def active_segment_ids_with_children
  children = embedded_children.reduce([]) do |memo, child|
    memo += child.active_segment_ids if child.respond_to?(:active_segment_ids)
    memo
  end

  (active_segment_ids + children).uniq
end

#segmented?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/models/workarea/segmentable.rb', line 53

def segmented?
  active_segment_ids.present?
end

#segmentsObject



57
58
59
# File 'app/models/workarea/segmentable.rb', line 57

def segments
  @segments ||= active_segment_ids.blank? ? [] : Segment.in(id: active_segment_ids)
end