We're going to make it dynamic using the geozones. Besides, class methods can be overwritten using custom models, while constants can't be overwritten without getting a warning [1]. Makes the definition of segments with geozones a little cleaner. I think it’s worth it, compared to the slight memory gain of using a constant [2]. [1] warning: already initialized constant UserSegments::SEGMENTS [2] https://stackoverflow.com/questions/15903835/class-method-vs-constant-in-ruby-rails#answer-15903970
16 lines
444 B
Ruby
16 lines
444 B
Ruby
module UserSegmentsHelper
|
|
def user_segments_options
|
|
UserSegments.segments.map do |user_segment_name|
|
|
[t("admin.segment_recipient.#{user_segment_name}"), user_segment_name]
|
|
end
|
|
end
|
|
|
|
def segment_name(user_segment)
|
|
if user_segment && UserSegments.respond_to?(user_segment)
|
|
I18n.t("admin.segment_recipient.#{user_segment}")
|
|
else
|
|
I18n.t("admin.segment_recipient.invalid_recipients_segment")
|
|
end
|
|
end
|
|
end
|