Module: Detour::Concerns::Matchers
- Included in:
- Feature
- Defined in:
- app/models/detour/concerns/matchers.rb
Instance Method Summary collapse
-
#match?(instance) ⇒ Boolean
Determines whether or not the given instance has had the feature rolled out to it either via direct flagging-in, percentage, or by database or defined group membership.
-
#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_id?(instance) ⇒ Boolean
Determines whether or not the given instance has had the feature rolled out to it via direct flagging-in.
-
#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?(instance) ⇒ Boolean
Determines whether or not the given instance has had the feature rolled out to it either via direct flagging-in, percentage, or by database or defined group membership.
14 15 16 17 18 19 |
# File 'app/models/detour/concerns/matchers.rb', line 14 def match?(instance) match_id?(instance) || match_percentage?(instance) || match_database_groups?(instance) || match_defined_groups?(instance) end |
#match_database_groups?(instance) ⇒ Boolean
Determines whether or not the given instance has had the feature rolled out to it via database group membership.
65 66 67 |
# File 'app/models/detour/concerns/matchers.rb', line 65 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.
80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/models/detour/concerns/matchers.rb', line 80 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_id?(instance) ⇒ Boolean
Determines whether or not the given instance has had the feature rolled out to it via direct flagging-in.
32 33 34 |
# File 'app/models/detour/concerns/matchers.rb', line 32 def match_id?(instance) flag_in_flags.where(flaggable_type: instance.class.to_s, flaggable_id: instance.id).any? end |
#match_percentage?(instance) ⇒ Boolean
Determines whether or not the given instance has had the feature rolled out to it via percentage.
47 48 49 50 51 52 |
# File 'app/models/detour/concerns/matchers.rb', line 47 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 |