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 +4 -4
- data/README.md +1 -1
- data/app/models/detour/feature.rb +9 -4
- data/lib/detour/configuration.rb +20 -4
- data/lib/detour/version.rb +1 -1
- data/spec/controllers/detour/flags_controller_spec.rb +1 -1
- data/spec/dummy/config/initializers/detour.rb +1 -1
- data/spec/features/features_spec.rb +1 -1
- data/spec/lib/detour/configuration_spec.rb +15 -0
- data/spec/lib/detour/flag_form_spec.rb +1 -1
- data/spec/models/detour/feature_spec.rb +19 -1
- data/spec/spec_helper.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ca146964bc97965e5f1b493fb87c8c4fcd2b149
|
4
|
+
data.tar.gz: da57f56e5998a03bc6559958a9dcc54f2bf62629
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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 `@
|
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 `@
|
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.
|
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(
|
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
|
data/lib/detour/configuration.rb
CHANGED
@@ -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 :
|
6
|
+
attr_accessor :feature_search_dirs
|
6
7
|
|
7
8
|
def initialize
|
8
|
-
@defined_groups
|
9
|
-
@flaggable_types
|
10
|
-
@
|
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
|
data/lib/detour/version.rb
CHANGED
@@ -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
|
@@ -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.
|
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