Class: ActionController::Base
- Inherits:
-
Object
- Object
- ActionController::Base
- Defined in:
- lib/fluidfeatures/rails.rb
Instance Attribute Summary collapse
-
#ff_transaction ⇒ Object
Returns the value of attribute ff_transaction.
Instance Method Summary collapse
-
#fluidfeature(feature_name, version_name = nil, default_enabled = nil) ⇒ Object
(also: #ff?)
This is called by the developer’s code to determine if the feature, specified by “feature_name” is enabled for the current user.
- #fluidfeatures_default_enabled ⇒ Object
- #fluidfeatures_default_version_name ⇒ Object
-
#fluidfeatures_initialize_user ⇒ Object
Here is how we know what your user_id is for the user making the current request.
-
#fluidfeatures_request_after ⇒ Object
After the rails request is complete we will log which features we encountered, including the default settings (eg. enabled) for each feature.
-
#fluidfeatures_request_before ⇒ Object
Initialize the FluidFeatures state for this request.
-
#fluidfeatures_retrieve_user_features ⇒ Object
Returns the features enabled for this request’s user.
- #fluidgoal(goal_name, goal_version_name = nil) ⇒ Object
Instance Attribute Details
#ff_transaction ⇒ Object
Returns the value of attribute ff_transaction.
69 70 71 |
# File 'lib/fluidfeatures/rails.rb', line 69 def ff_transaction @ff_transaction end |
Instance Method Details
#fluidfeature(feature_name, version_name = nil, default_enabled = nil) ⇒ Object Also known as: ff?
This is called by the developer’s code to determine if the feature, specified by “feature_name” is enabled for the current user. We call user_id to get the current user’s unique id.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/fluidfeatures/rails.rb', line 139 def fluidfeature(feature_name, version_name=nil, default_enabled=nil) # also support: fluidfeature(feature_name, default_enabled) if default_enabled == nil and (version_name.is_a? FalseClass or version_name.is_a? TrueClass) default_enabled = version_name version_name = nil end unless default_enabled.is_a? FalseClass or default_enabled.is_a? TrueClass default_enabled = fluidfeatures_default_enabled end unless ::FluidFeatures::Rails.enabled return default_enabled || false end ff_transaction.feature_enabled?(feature_name, version_name, default_enabled) end |
#fluidfeatures_default_enabled ⇒ Object
183 184 185 186 187 |
# File 'lib/fluidfeatures/rails.rb', line 183 def fluidfeatures_default_enabled # By default unknown features are disabled. # Override and return "true" to have features enabled by default. false end |
#fluidfeatures_default_version_name ⇒ Object
189 190 191 |
# File 'lib/fluidfeatures/rails.rb', line 189 def fluidfeatures_default_version_name "default" end |
#fluidfeatures_initialize_user ⇒ Object
Here is how we know what your user_id is for the user making the current request. This must be overriden within the user application. We recommend doing this in application_controller.rb
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/fluidfeatures/rails.rb', line 82 def fluidfeatures_initialize_user # call app defined method "fluidfeatures_current_user" user = nil begin user = fluidfeatures_current_user(verbose=true) || {} rescue NoMethodError raise FFeaturesException.new("Method fluidfeatures_current_user is not defined in your ApplicationController") end unless user.is_a? Hash raise FFeaturesException.new("fluidfeatures_current_user returned invalid user (Hash or nil expected) : #{user}") end # default to anonymous is no user id given user[:anonymous] = false unless user[:id] # if no user id given, then attempt to get the unique id of this visitor from the cookie user[:id] ||= [:fluidfeatures_anonymous] url = "#{request.protocol}#{request.host_with_port}#{request.fullpath}" transaction = ::FluidFeatures::Rails.ff_app.user_transaction( user[:id], url, user[:name], !!user[:anonymous], user[:uniques], user[:cohorts] ) # Set/delete cookies for anonymous users if transaction.user.anonymous # update the cookie, with the unique id of this user [:fluidfeatures_anonymous] = transaction.user.unique_id else # We are no longer an anoymous user. Delete the cookie if .has_key? :fluidfeatures_anonymous .delete(:fluidfeatures_anonymous) end end transaction end |
#fluidfeatures_request_after ⇒ Object
After the rails request is complete we will log which features we encountered, including the default settings (eg. enabled) for each feature. This helps the FluidFeatures database prepopulate the feature set without requiring the developer to do it manually.
179 180 181 |
# File 'lib/fluidfeatures/rails.rb', line 179 def fluidfeatures_request_after ff_transaction.end_transaction end |
#fluidfeatures_request_before ⇒ Object
Initialize the FluidFeatures state for this request.
129 130 131 |
# File 'lib/fluidfeatures/rails.rb', line 129 def fluidfeatures_request_before @ff_transaction = fluidfeatures_initialize_user end |
#fluidfeatures_retrieve_user_features ⇒ Object
Returns the features enabled for this request’s user.
168 169 170 |
# File 'lib/fluidfeatures/rails.rb', line 168 def fluidfeatures_retrieve_user_features ff_transaction.features end |
#fluidgoal(goal_name, goal_version_name = nil) ⇒ Object
158 159 160 161 162 163 |
# File 'lib/fluidfeatures/rails.rb', line 158 def fluidgoal(goal_name, goal_version_name=nil) unless ::FluidFeatures::Rails.enabled return default_enabled || false end ff_transaction.goal_hit(goal_name, goal_version_name) end |