Module: GreenFlag::SiteVisitorManagement
- Defined in:
- app/controllers/green_flag/site_visitor_management.rb
Constant Summary collapse
- COOKIE_NAME =
'green_flag_site_visitor'
Class Method Summary collapse
Instance Method Summary collapse
-
#current_site_visitor ⇒ Object
Finds or creates a GreenFlag::SiteVisitor.
- #feature_enabled?(feature_code) ⇒ Boolean
-
#record_login(user) ⇒ Object
Make sure the current SiteVisitor is the correct visitor for this user.
-
#set_site_visitor ⇒ Object
Ensure we have a cookie.
Class Method Details
.included(base) ⇒ Object
4 5 6 7 |
# File 'app/controllers/green_flag/site_visitor_management.rb', line 4 def self.included(base) base.before_filter :set_site_visitor base.helper_method :feature_enabled? end |
Instance Method Details
#current_site_visitor ⇒ Object
Finds or creates a GreenFlag::SiteVisitor
21 22 23 24 25 26 |
# File 'app/controllers/green_flag/site_visitor_management.rb', line 21 def current_site_visitor @current_site_visitor ||= begin code = GreenFlag::SiteVisitor.for_visitor_code!(code) end end |
#feature_enabled?(feature_code) ⇒ Boolean
28 29 30 31 32 33 34 35 |
# File 'app/controllers/green_flag/site_visitor_management.rb', line 28 def feature_enabled?(feature_code) @features_enabled ||= {} if @features_enabled[feature_code].nil? visitor_id = current_site_visitor.id @features_enabled[feature_code] = GreenFlag::FeatureDecision.feature_enabled?(feature_code, visitor_id) end @features_enabled[feature_code] end |
#record_login(user) ⇒ Object
Make sure the current SiteVisitor is the correct visitor for this user
16 17 18 |
# File 'app/controllers/green_flag/site_visitor_management.rb', line 16 def record_login(user) self.current_site_visitor = GreenFlag::SiteVisitor.for_user!(user, current_site_visitor) end |
#set_site_visitor ⇒ Object
Ensure we have a cookie
10 11 12 13 |
# File 'app/controllers/green_flag/site_visitor_management.rb', line 10 def set_site_visitor record_login(current_user) if current_user end |