Module: Detour::Concerns::Matchers
- Included in:
- Feature
- Defined in:
- app/models/detour/concerns/matchers.rb
Instance Method Summary collapse
-
#match_database_groups?(instance) ⇒ Boolean
Determines whether or not the given instance has had the feature rolled out to it via database group membership.
-
#match_defined_groups?(instance) ⇒ Boolean
Determines whether or not the given instance has had the feature rolled out to it via defined group membership.
-
#match_percentage?(instance) ⇒ Boolean
Determines whether or not the given instance has had the feature rolled out to it via percentage.
Instance Method Details
#match_database_groups?(instance) ⇒ Boolean
Determines whether or not the given instance has had the feature rolled out to it via database group membership.
32 33 34 |
# File 'app/models/detour/concerns/matchers.rb', line 32 def match_database_groups?(instance) database_group_flags.where(flaggable_type: instance.class).map(&:members).flatten.uniq.include? instance end |
#match_defined_groups?(instance) ⇒ Boolean
Determines whether or not the given instance has had the feature rolled out to it via defined group membership.
47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/detour/concerns/matchers.rb', line 47 def match_defined_groups?(instance) klass = instance.class.to_s return unless Detour::DefinedGroup.by_type(klass).any? group_names = defined_group_flags.find_all_by_flaggable_type(klass).collect(&:group_name) Detour::DefinedGroup.by_type(klass).collect { |name, group| group.test(instance) if group_names.include? group.name }.any? end |
#match_percentage?(instance) ⇒ Boolean
Determines whether or not the given instance has had the feature rolled out to it via percentage.
14 15 16 17 18 19 |
# File 'app/models/detour/concerns/matchers.rb', line 14 def match_percentage?(instance) flag = percentage_flags.find(:first, conditions: ["flaggable_type = ?", instance.class.to_s]) percentage = flag ? flag.percentage : 0 instance.id % 10 < percentage / 10 end |