Module: Detour::Concerns::FlagActions::ClassMethods
- Defined in:
- app/models/detour/concerns/flag_actions.rb
Instance Method Summary collapse
-
#add_group_to_feature(flaggable_type, group_name, feature_name) ⇒ Detour::Flag
Add a group to the given feature.
-
#add_percentage_to_feature(flaggable_type, percentage, feature_name) ⇒ Detour::Flag
Add a percentage of records to the given feature.
-
#add_record_to_feature(record, feature_name) ⇒ Detour::Flag
Add a record to the given feature.
-
#opt_record_out_of_feature(record, feature_name) ⇒ Detour::OptOut
Opt the given record out of a feature.
-
#remove_group_from_feature(flaggable_type, group_name, feature_name) ⇒ Object
Remove a group from agiven feature.
-
#remove_percentage_from_feature(flaggable_type, feature_name) ⇒ Object
Remove any percentage flags for the given feature.
-
#remove_record_from_feature(record, feature_name) ⇒ Object
Remove a record from the given feature.
-
#un_opt_record_out_of_feature(record, feature_name) ⇒ Object
Remove any opt out for the given record out of a feature.
Instance Method Details
#add_group_to_feature(flaggable_type, group_name, feature_name) ⇒ Detour::Flag
Add a group to the given feature. If the feature is not found, an ActiveRecord::RecordNotFound will be raised.
81 82 83 84 |
# File 'app/models/detour/concerns/flag_actions.rb', line 81 def add_group_to_feature(flaggable_type, group_name, feature_name) feature = find_by_name!(feature_name) feature.group_flags.where(flaggable_type: flaggable_type, group_name: group_name).first_or_create! end |
#add_percentage_to_feature(flaggable_type, percentage, feature_name) ⇒ Detour::Flag
Add a percentage of records to the given feature. If the feature is not found, an ActiveRecord::RecordNotFound will be raised.
118 119 120 121 122 123 |
# File 'app/models/detour/concerns/flag_actions.rb', line 118 def add_percentage_to_feature(flaggable_type, percentage, feature_name) feature = find_by_name!(feature_name) flag = feature.percentage_flags.where(flaggable_type: flaggable_type).first_or_initialize flag.update_attributes!(percentage: percentage) end |
#add_record_to_feature(record, feature_name) ⇒ Detour::Flag
Add a record to the given feature. If the feature is not found, an ActiveRecord::RecordNotFound will be raised.
17 18 19 20 |
# File 'app/models/detour/concerns/flag_actions.rb', line 17 def add_record_to_feature(record, feature_name) feature = find_by_name!(feature_name) feature.flag_in_flags.where(flaggable_type: record.class.to_s, flaggable_id: record.id).first_or_create! end |
#opt_record_out_of_feature(record, feature_name) ⇒ Detour::OptOut
Opt the given record out of a feature. If the feature is not found, an ActiveRecord::RecordNotFound will be raised. An opt out ensures that no matter what, ‘record.rollout?(:rollout)` will always return false for any opted-out-of features.
49 50 51 52 |
# File 'app/models/detour/concerns/flag_actions.rb', line 49 def opt_record_out_of_feature(record, feature_name) feature = find_by_name!(feature_name) feature.opt_out_flags.where(flaggable_type: record.class.to_s, flaggable_id: record.id).first_or_create! end |
#remove_group_from_feature(flaggable_type, group_name, feature_name) ⇒ Object
Remove a group from agiven feature. If the feature is not found, an ActiveRecord::RecordNotFound will be raised.
98 99 100 101 |
# File 'app/models/detour/concerns/flag_actions.rb', line 98 def remove_group_from_feature(flaggable_type, group_name, feature_name) feature = find_by_name!(feature_name) feature.group_flags.where(flaggable_type: flaggable_type, group_name: group_name).destroy_all end |
#remove_percentage_from_feature(flaggable_type, feature_name) ⇒ Object
Remove any percentage flags for the given feature. If the feature is not found, an ActiveRecord::RecordNotFound will be raised.
135 136 137 138 |
# File 'app/models/detour/concerns/flag_actions.rb', line 135 def remove_percentage_from_feature(flaggable_type, feature_name) feature = find_by_name!(feature_name) feature.percentage_flags.where(flaggable_type: flaggable_type).destroy_all end |
#remove_record_from_feature(record, feature_name) ⇒ Object
Remove a record from the given feature. If the feature is not found, an ActiveRecord::RecordNotFound will be raised.
31 32 33 34 |
# File 'app/models/detour/concerns/flag_actions.rb', line 31 def remove_record_from_feature(record, feature_name) feature = find_by_name!(feature_name) feature.flag_in_flags.where(flaggable_type: record.class.to_s, flaggable_id: record.id).destroy_all end |
#un_opt_record_out_of_feature(record, feature_name) ⇒ Object
Remove any opt out for the given record out of a feature. If the feature is not found, an ActiveRecord::RecordNotFound will be raised.
62 63 64 65 |
# File 'app/models/detour/concerns/flag_actions.rb', line 62 def un_opt_record_out_of_feature(record, feature_name) feature = find_by_name!(feature_name) feature.opt_out_flags.where(flaggable_type: record.class.to_s, flaggable_id: record.id).destroy_all end |