time_pilot 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/time_pilot/time_pilot.rb +29 -13
- data/lib/time_pilot/version.rb +1 -1
- data/test/time_pilot_test.rb +59 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1035c965584954a3de7fbee71027d0d081c2c8a99521f1590fd9f6ad00f84438
|
4
|
+
data.tar.gz: 01bc1de61e0911ca0e60f464d2869028a9b22556ea0f6c5ec71163d5d3b4b979
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d477c3f65330966a93de7ba0088b24771f38d6cbc9a280a1dfa6382d30ce01fe025df2f31d9aa734a366587e545f2bc2e7e7d85aeb9220c77513603ab9ecc36
|
7
|
+
data.tar.gz: 2f790748fcdcd320ee06fdfafacef5facd3400dce9a807f1f6998647622b3155519b865e8f9a6f139491d3b9a291f1947b49c866568774362fa9b990d3416dec
|
@@ -16,21 +16,23 @@ module TimePilot
|
|
16
16
|
def self.configure
|
17
17
|
@config ||= Configuration.new
|
18
18
|
yield @config
|
19
|
-
@config.features.each { |f|
|
19
|
+
@config.features.each { |f| define_feature_methods(f) }
|
20
20
|
end
|
21
21
|
|
22
|
-
def self.
|
22
|
+
def self.define_feature_methods(feature_name)
|
23
23
|
Features.module_eval do
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
unless method_defined?("enable_#{feature_name}")
|
25
|
+
define_method "enable_#{feature_name}" do
|
26
|
+
pilot_enable_feature(feature_name)
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
define_method "disable_#{feature_name}" do
|
30
|
+
pilot_disable_feature(feature_name)
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
33
|
+
define_method "#{feature_name}_enabled?" do
|
34
|
+
pilot_feature_enabled?(feature_name)
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
@@ -70,22 +72,36 @@ module TimePilot
|
|
70
72
|
def pilot_enable_feature(feature_name)
|
71
73
|
key_name = "#{feature_name}:#{self.class.to_s.underscore}_ids"
|
72
74
|
TimePilot.redis.sadd TimePilot.key(key_name), id
|
75
|
+
instance_variable_set("@#{feature_name}_enabled", true)
|
73
76
|
end
|
74
77
|
|
75
78
|
def pilot_disable_feature(feature_name)
|
76
79
|
key_name = "#{feature_name}:#{self.class.to_s.underscore}_ids"
|
77
80
|
TimePilot.redis.srem TimePilot.key(key_name), id
|
81
|
+
instance_variable_set("@#{feature_name}_enabled", false)
|
78
82
|
end
|
79
83
|
|
80
84
|
def pilot_feature_enabled?(feature_name)
|
85
|
+
unless instance_variable_defined?("@#{feature_name}_enabled")
|
86
|
+
instance_variable_set("@#{feature_name}_enabled",
|
87
|
+
pilot_member_in_any_group?(feature_name))
|
88
|
+
end
|
89
|
+
instance_variable_get("@#{feature_name}_enabled")
|
90
|
+
end
|
91
|
+
|
92
|
+
def pilot_member_in_any_group?(feature_name)
|
81
93
|
TimePilot.redis.pipelined do
|
82
94
|
self.class.time_pilot_groups.each do |group|
|
83
|
-
|
84
|
-
|
95
|
+
TimePilot.redis.sismember(
|
96
|
+
TimePilot.key("#{feature_name}:#{group}_ids"),
|
97
|
+
send(pilot_method_for_group(group))
|
98
|
+
)
|
85
99
|
end
|
86
100
|
end.include? true
|
87
101
|
end
|
88
102
|
|
103
|
+
def pilot_method_for_group(group_name)
|
104
|
+
group_name.to_s == self.class.to_s.underscore ? 'id' : group_name + '_id'
|
105
|
+
end
|
89
106
|
end
|
90
|
-
|
91
107
|
end
|
data/lib/time_pilot/version.rb
CHANGED
data/test/time_pilot_test.rb
CHANGED
@@ -59,6 +59,7 @@ describe TimePilot do
|
|
59
59
|
it 'defines a getter on company' do
|
60
60
|
TimePilot.redis.sadd 'timepilot:planning:company_ids', @acme.id
|
61
61
|
@acme.planning_enabled?.must_equal true
|
62
|
+
@acme.instance_variable_get("@planning_enabled").must_equal true
|
62
63
|
end
|
63
64
|
|
64
65
|
it 'defines an enabler on company' do
|
@@ -69,8 +70,10 @@ describe TimePilot do
|
|
69
70
|
it 'defines a disabler on employee' do
|
70
71
|
@nedap.enable_planning
|
71
72
|
@nedap.planning_enabled?.must_equal true
|
73
|
+
@nedap.instance_variable_get("@planning_enabled").must_equal true
|
72
74
|
@nedap.disable_planning
|
73
75
|
@nedap.planning_enabled?.must_equal false
|
76
|
+
@nedap.instance_variable_get("@planning_enabled").must_equal false
|
74
77
|
end
|
75
78
|
|
76
79
|
it 'defines a getter on team' do
|
@@ -86,13 +89,16 @@ describe TimePilot do
|
|
86
89
|
it 'defines a disabler on team' do
|
87
90
|
@retail.enable_planning
|
88
91
|
@retail.planning_enabled?.must_equal true
|
92
|
+
@retail.instance_variable_get("@planning_enabled").must_equal true
|
89
93
|
@retail.disable_planning
|
90
94
|
@retail.planning_enabled?.must_equal false
|
95
|
+
@retail.instance_variable_get("@planning_enabled").must_equal false
|
91
96
|
end
|
92
97
|
|
93
98
|
it 'defines a getter on employee' do
|
94
99
|
TimePilot.redis.sadd 'timepilot:planning:employee_ids', @john.id
|
95
100
|
@john.planning_enabled?.must_equal true
|
101
|
+
@john.instance_variable_get("@planning_enabled").must_equal true
|
96
102
|
end
|
97
103
|
|
98
104
|
it 'defines an enabler on employee' do
|
@@ -103,8 +109,10 @@ describe TimePilot do
|
|
103
109
|
it 'defines a disabler on employee' do
|
104
110
|
@jane.enable_planning
|
105
111
|
@jane.planning_enabled?.must_equal true
|
112
|
+
@jane.instance_variable_get("@planning_enabled").must_equal true
|
106
113
|
@jane.disable_planning
|
107
114
|
@jane.planning_enabled?.must_equal false
|
115
|
+
@jane.instance_variable_get("@planning_enabled").must_equal false
|
108
116
|
end
|
109
117
|
|
110
118
|
it 'defines a cardinality count on the classes' do
|
@@ -125,16 +133,19 @@ describe TimePilot do
|
|
125
133
|
specify 'company overrides team' do
|
126
134
|
@nedap.enable_planning
|
127
135
|
@retail.planning_enabled?.must_equal true
|
136
|
+
@retail.instance_variable_get("@planning_enabled").must_equal true
|
128
137
|
end
|
129
138
|
|
130
139
|
specify 'team overrides employee' do
|
131
140
|
@healthcare.enable_planning
|
132
141
|
@john.planning_enabled?.must_equal true
|
142
|
+
@john.instance_variable_get("@planning_enabled").must_equal true
|
133
143
|
end
|
134
144
|
|
135
145
|
specify 'company overrides employee' do
|
136
146
|
@nedap.enable_planning
|
137
147
|
@jane.planning_enabled?.must_equal true
|
148
|
+
@jane.instance_variable_get("@planning_enabled").must_equal true
|
138
149
|
end
|
139
150
|
end
|
140
151
|
|
@@ -148,3 +159,51 @@ describe TimePilot, 'converting CamelCase to camel_case' do
|
|
148
159
|
CamelCasedModel.time_pilot_groups.must_equal ['camel_cased_model']
|
149
160
|
end
|
150
161
|
end
|
162
|
+
|
163
|
+
describe TimePilot do
|
164
|
+
before do
|
165
|
+
@acme = Company.new(1)
|
166
|
+
|
167
|
+
@mock = MiniTest::Mock.new
|
168
|
+
TimePilot.configure do |config|
|
169
|
+
config.redis(@mock)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
after do
|
174
|
+
TimePilot.configure do |config|
|
175
|
+
config.redis(Redis.new)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
specify 'calls redis only once' do
|
180
|
+
@mock.expect(:pipelined, [true])
|
181
|
+
|
182
|
+
@acme.planning_enabled?.must_equal true
|
183
|
+
# Call the feature a second time
|
184
|
+
# If it calls redis you will get
|
185
|
+
# MockExpectationError: No more expects available for :pipelined: []
|
186
|
+
@acme.planning_enabled?.must_equal true
|
187
|
+
end
|
188
|
+
|
189
|
+
specify 'does not call redis to get status after disabling' do
|
190
|
+
@mock.expect(:srem, true, ['timepilot:planning:company_ids', @acme.id])
|
191
|
+
|
192
|
+
@acme.disable_planning
|
193
|
+
# Call the feature again it should hit the instance variable
|
194
|
+
# If it calls redis you will get
|
195
|
+
# MockExpectationError: No more expects available for :pipelined: []
|
196
|
+
@acme.planning_enabled?.must_equal false
|
197
|
+
end
|
198
|
+
|
199
|
+
specify 'does not call redis to get status after enabling' do
|
200
|
+
@mock.expect(:sadd, true, ['timepilot:planning:company_ids', @acme.id])
|
201
|
+
|
202
|
+
@acme.enable_planning
|
203
|
+
# Call the feature again it should hit the instance variable
|
204
|
+
# If it calls redis you will get
|
205
|
+
# MockExpectationError: No more expects available for :pipelined: []
|
206
|
+
@acme.planning_enabled?.must_equal true
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_pilot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@mlangenberg"
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-09-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
100
|
version: '0'
|
101
101
|
requirements: []
|
102
102
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.
|
103
|
+
rubygems_version: 2.7.6
|
104
104
|
signing_key:
|
105
105
|
specification_version: 4
|
106
106
|
summary: Configure enabled features for a specific set of users.
|