Class: Detour::Feature
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Detour::Feature
- Includes:
- Concerns::CustomHumanAttributes
- Defined in:
- app/models/detour/feature.rb
Overview
Represents an individual feature that may be rolled out to a set of records via individual flags, percentages, or defined groups.
Class Method Summary collapse
-
.with_lines ⇒ Array<Detour::Feature>
Return an array of both every feature in the database as well as every feature that is checked for in ‘@feature_search_dirs`.
Instance Method Summary collapse
-
#flag_in_count_for(type) ⇒ Fixnum
Returns the number of flag-ins for a given type.
-
#lines ⇒ Array<String>
Returns an instance variable intended to hold an array of the lines of code that this feature appears on.
-
#opt_out_count_for(type) ⇒ Fixnum
Returns the number of opt-outs for a given type.
- #to_s ⇒ Object
Class Method Details
.with_lines ⇒ Array<Detour::Feature>
Return an array of both every feature in the database as well as every feature that is checked for in ‘@feature_search_dirs`. Features that are checked for but not persisted will be returned as unpersisted instances of this class. Each instance returned will have its `@lines` set to an array containing every line in `@feature_search_dirs` where it is checked for.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/models/detour/feature.rb', line 65 def self.with_lines hash = all.each_with_object({}) { |feature, hash| hash[feature.name] = feature } Dir[*Detour.config.feature_search_dirs].each do |path| next unless File.file? path File.open path do |file| file.each_line.with_index(1) do |line, i| line.scan(feature_search_regex).each do |match, _| (hash[match] ||= new(name: match)).lines << "#{path}#L#{i}" end end end end hash.values.sort_by(&:name) end |
Instance Method Details
#flag_in_count_for(type) ⇒ Fixnum
Returns the number of flag-ins for a given type.
43 44 45 |
# File 'app/models/detour/feature.rb', line 43 def flag_in_count_for(type) flag_in_counts[type] || 0 end |
#lines ⇒ Array<String>
Returns an instance variable intended to hold an array of the lines of code that this feature appears on.
29 30 31 |
# File 'app/models/detour/feature.rb', line 29 def lines @lines ||= [] end |
#opt_out_count_for(type) ⇒ Fixnum
Returns the number of opt-outs for a given type.
53 54 55 |
# File 'app/models/detour/feature.rb', line 53 def opt_out_count_for(type) opt_out_counts[type] || 0 end |
#to_s ⇒ Object
33 34 35 |
# File 'app/models/detour/feature.rb', line 33 def to_s name end |