detour 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f0d93b6f88bfbc32c18a69476133c35adbc77a7
4
- data.tar.gz: 64fd4443f00d265b48f3fdff2d7124c590bfd994
3
+ metadata.gz: 8ca146964bc97965e5f1b493fb87c8c4fcd2b149
4
+ data.tar.gz: da57f56e5998a03bc6559958a9dcc54f2bf62629
5
5
  SHA512:
6
- metadata.gz: d4cb09c0a64c6754a6987703695cda08a5205bfa954af3137be55cf1291b31a34d3c5fb487b0814aa7328af0dc44b06654e249f0714ffef8b831718ccb9d68e1
7
- data.tar.gz: 080c630df51ba8a28bad603fb088256ec9a370f2aab18c8d3567fd0e7568fea54a0be1bb7ef84b28a93d70b70d692e0dc05dc4fbf6e1690306ba402cd723dd15
6
+ metadata.gz: 4cdaf7bcfec46bdadbbc147f6baaddabf373fe610172afb531805f82250c3b292581281ba5a11aeeaac98dd87fd77ceb4e980d4165a7e0ca0a07fa2c1a8245e8
7
+ data.tar.gz: d2535f168cadb5ff31bcd23055d96cac22971d8521a97903407563de976b741faada4ade8cb1ed826edb71ef8e94cac4439c38161787bec14de9be9ef13541b2
data/README.md CHANGED
@@ -60,7 +60,7 @@ Detour.configure do |config|
60
60
  # through in order to find places where you're
61
61
  # checking for flags in your code. Provide it an
62
62
  # array of glob strings:
63
- config.grep_dirs = %w[app/**/*.{rb,erb}]
63
+ config.feature_search_dirs = %w[app/**/*.{rb,erb}]
64
64
 
65
65
  # Provide a default class to manage rollouts for, if
66
66
  # desired. This means you can omit the class name from
@@ -55,22 +55,22 @@ class Detour::Feature < ActiveRecord::Base
55
55
  end
56
56
 
57
57
  # Return an array of both every feature in the database as well as every
58
- # feature that is checked for in `@grep_dirs`. Features that are checked
58
+ # feature that is checked for in `@feature_search_dirs`. Features that are checked
59
59
  # for but not persisted will be returned as unpersisted instances of this
60
60
  # class. Each instance returned will have its `@lines` set to an array
61
- # containing every line in `@grep_dirs` where it is checked for.
61
+ # containing every line in `@feature_search_dirs` where it is checked for.
62
62
  #
63
63
  # @return [Array<Detour::Feature>] Every persisted and
64
64
  # checked-for feature.
65
65
  def self.with_lines
66
66
  hash = all.each_with_object({}) { |feature, hash| hash[feature.name] = feature }
67
67
 
68
- Dir[*Detour.config.grep_dirs].each do |path|
68
+ Dir[*Detour.config.feature_search_dirs].each do |path|
69
69
  next unless File.file? path
70
70
 
71
71
  File.open path do |file|
72
72
  file.each_line.with_index(1) do |line, i|
73
- line.scan(/\.has_feature\?\s*\(?[:"]([\w-]+)/).each do |match, _|
73
+ line.scan(feature_search_regex).each do |match, _|
74
74
  (hash[match] ||= new(name: match)).lines << "#{path}#L#{i}"
75
75
  end
76
76
  end
@@ -79,4 +79,9 @@ class Detour::Feature < ActiveRecord::Base
79
79
 
80
80
  hash.values.sort_by(&:name)
81
81
  end
82
+
83
+ def self.feature_search_regex
84
+ Detour.config.feature_search_regex || /\.has_feature\?\s*\(?[:"]([\w-]+)/
85
+ end
86
+ private_class_method :feature_search_regex
82
87
  end
@@ -1,13 +1,29 @@
1
1
  class Detour::Configuration
2
2
  attr_reader :defined_groups
3
+ attr_reader :feature_search_regex
3
4
  attr_accessor :default_flaggable_class_name
4
5
  attr_accessor :flaggable_types
5
- attr_accessor :grep_dirs
6
+ attr_accessor :feature_search_dirs
6
7
 
7
8
  def initialize
8
- @defined_groups = {}
9
- @flaggable_types = []
10
- @grep_dirs = []
9
+ @defined_groups = {}
10
+ @flaggable_types = []
11
+ @feature_search_dirs = []
12
+ end
13
+
14
+ # Defines the regular expression used to search for features. It must include
15
+ # a single match group.
16
+ #
17
+ # @example
18
+ # Detour.config.feature_search_regex = /\.rollout\? :(\w+)/
19
+ #
20
+ # @param [Regexp] regex A regex to use to search for feature checks with.
21
+ def feature_search_regex=(regex)
22
+ if regex.is_a? Regexp
23
+ @feature_search_regex = regex
24
+ else
25
+ raise "Feature search regex must be an instance of Regexp"
26
+ end
11
27
  end
12
28
 
13
29
  # Allows for methods of the form `define_user_group` that call the private
@@ -1,3 +1,3 @@
1
1
  module Detour
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -5,7 +5,7 @@ describe Detour::FlagsController do
5
5
 
6
6
  describe "GET #index" do
7
7
  before do
8
- Detour.config.grep_dirs = ["spec/dummy/app/**/*.{rb,erb}"]
8
+ Detour.config.feature_search_dirs = ["spec/dummy/app/**/*.{rb,erb}"]
9
9
  get :index, flaggable_type: "users"
10
10
  end
11
11
 
@@ -3,7 +3,7 @@ Detour.configure do |config|
3
3
  # user.admin?
4
4
  # end
5
5
 
6
- config.grep_dirs = %w[app/**/*.{rb,erb}]
6
+ config.feature_search_dirs = %w[app/**/*.{rb,erb}]
7
7
 
8
8
  config.flaggable_types = %w[User Widget]
9
9
 
@@ -15,7 +15,7 @@ describe "listing features for a type" do
15
15
 
16
16
 
17
17
  before do
18
- Detour.config.grep_dirs = %w[spec/dummy/app/**/*.{rb,erb}]
18
+ Detour.config.feature_search_dirs = %w[spec/dummy/app/**/*.{rb,erb}]
19
19
  visit "/detour/flags/users"
20
20
  end
21
21
 
@@ -17,6 +17,21 @@ describe Detour::Configuration do
17
17
  end
18
18
  end
19
19
 
20
+ describe ".feature_search_regex=" do
21
+ context "when given a regex" do
22
+ it "sets the feature search regex" do
23
+ subject.feature_search_regex = /foo/
24
+ subject.feature_search_regex.should eq /foo/
25
+ end
26
+ end
27
+
28
+ context "when not given a regex" do
29
+ it "raises an exception" do
30
+ expect { subject.feature_search_regex = "string" }.to raise_error "Feature search regex must be an instance of Regexp"
31
+ end
32
+ end
33
+ end
34
+
20
35
  describe ".define_{klass}_group" do
21
36
  let(:block) { Proc.new {} }
22
37
  it "defines a group for the given class" do
@@ -7,7 +7,7 @@ describe Detour::FlagForm do
7
7
 
8
8
  describe "#features" do
9
9
  before do
10
- Detour.config.grep_dirs = ["spec/dummy/app/**/*.{rb,erb}"]
10
+ Detour.config.feature_search_dirs = ["spec/dummy/app/**/*.{rb,erb}"]
11
11
  end
12
12
 
13
13
  it "returns every feature including lines" do
@@ -32,7 +32,7 @@ describe Detour::Feature do
32
32
  let(:feature) { create :feature, name: "foo" }
33
33
 
34
34
  before do
35
- Detour.config.grep_dirs = ["/foo/**/*.rb"]
35
+ Detour.config.feature_search_dirs = ["/foo/**/*.rb"]
36
36
 
37
37
  FileUtils.mkdir("/foo")
38
38
 
@@ -46,6 +46,9 @@ describe Detour::Feature do
46
46
 
47
47
  current_user.has_feature?(:foo) do
48
48
  end
49
+
50
+ current_user.rollout?(:foo) do
51
+ end
49
52
  EOF
50
53
  end
51
54
 
@@ -59,6 +62,21 @@ describe Detour::Feature do
59
62
  end
60
63
  end
61
64
 
65
+ context "when there is a custom feature search regex" do
66
+ before do
67
+ Detour.config.feature_search_regex = /rollout\?\(:(\w+)\)/
68
+ end
69
+
70
+ after do
71
+ Detour.config.instance_variable_set "@feature_search_regex", nil
72
+ end
73
+
74
+ it "uses the custom feature search regex" do
75
+ persisted_feature = Detour::Feature.with_lines.detect { |f| f.name == feature.name }
76
+ persisted_feature.lines.should eq %w[/foo/bar.rb#L10]
77
+ end
78
+ end
79
+
62
80
  it "fetches lines for persisted features" do
63
81
  persisted_feature = Detour::Feature.with_lines.detect { |f| f.name == feature.name }
64
82
  persisted_feature.lines.should eq %w[/foo/bar.rb#L1 /foo/bar.rb#L7 /foo/baz.rb#L1]
data/spec/spec_helper.rb CHANGED
@@ -58,7 +58,7 @@ RSpec.configure do |config|
58
58
 
59
59
  config.after :each do
60
60
  Detour.config.default_flaggable_class_name = nil
61
- Detour.config.grep_dirs = []
61
+ Detour.config.feature_search_dirs = []
62
62
  Detour.config.instance_variable_set "@defined_groups", {}
63
63
  end
64
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: detour
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Clem