toggles 0.0.8 → 0.1.0

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: 161f954b81d64d3d1942e3f6b189bd7a1de45da8
4
- data.tar.gz: 6df537de28770b0a791b442afb3a7ac05439e0d0
3
+ metadata.gz: 4c6cab928b9d2ae109e343f8fc2080a03d5e0da6
4
+ data.tar.gz: 4aca8601e7c8b6857af5e2fc4a5e0414d3103a50
5
5
  SHA512:
6
- metadata.gz: 3605a942f1e9a914174d9d2f0683bbad7a8243ed2a0a2a39f8da0471c5a1e3710328255491ad3ece29c2356f776f342c72327dad9699dc50604f24be8e37fcc6
7
- data.tar.gz: a43cf2b9a274517d8f5ae269b4ccce0fb7868182706c51144584069af7a936301a9862fcfe6bddc1b03f1a7213fc833cfd76ce9ec5e9df630eccf05243bc324c
6
+ metadata.gz: 3e5c709861c01f380f9b96b36415f18f03f20dcbca802f1f3698d5838b57d399e88c6e008da98cb61f7a8709eeca7a7fc37f9813ce192e037f3b1e63c9459ab6
7
+ data.tar.gz: cf89cf95d9901490bc73d2f8dfab2b62159c4da89f1a02255d920fdccb3ee51a166fae52efce1164791194dfbad91d4d9195f5f62bdc19ce7e944c5f7477e0a9
@@ -0,0 +1,9 @@
1
+ data:
2
+ or:
3
+ id:
4
+ in: [1]
5
+ and:
6
+ id:
7
+ in: [2]
8
+ timestamp:
9
+ lt: 10
data/lib/toggles.rb CHANGED
@@ -1 +1,55 @@
1
+ require "toggles/configuration"
1
2
  require "toggles/feature"
3
+
4
+ module Toggles
5
+ extend self
6
+
7
+ def configure
8
+ yield configuration
9
+ init
10
+ end
11
+
12
+ def configuration
13
+ @configuration ||= Configuration.new
14
+ end
15
+
16
+ # Dynamically create modules and classes within the `Feature` module based on
17
+ # the directory structure of `features`.
18
+ #
19
+ # For example if the `features` directory has the structure:
20
+ #
21
+ # features
22
+ # ├── thing
23
+ # | ├── one.yml
24
+ # | └── two.yml
25
+ # └── test.yml
26
+ #
27
+ # `Feature::Test`, `Feature::Thing::One`, `Feature::Thing::Two` would be
28
+ # available by default.
29
+ #
30
+ def init
31
+ return unless Dir.exists? configuration.features_dir
32
+
33
+ Find.find(configuration.features_dir) do |path|
34
+ if path.match(/\.ya?ml\Z/)
35
+ _, *directories, filename = path.chomp(File.extname(path)).split("/")
36
+
37
+ previous = Feature
38
+ directories.each do |directory|
39
+ module_name = directory.split("_").map(&:capitalize).join.to_sym
40
+ previous = begin
41
+ previous.const_get(module_name)
42
+ rescue NameError
43
+ previous.const_set(module_name, Module.new)
44
+ end
45
+ end
46
+
47
+ cls = Class.new(Feature::Base) do |c|
48
+ c.const_set(:PERMISSIONS, Feature::Permissions.new(path))
49
+ end
50
+
51
+ previous.const_set(filename.split("_").map(&:capitalize).join.to_sym, cls)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,11 @@
1
+ module Toggles
2
+ class Configuration
3
+ def features_dir=(dir)
4
+ @features_dir = dir
5
+ end
6
+
7
+ def features_dir
8
+ @features_dir ||= "features"
9
+ end
10
+ end
11
+ end
@@ -14,42 +14,3 @@ module Feature
14
14
  or: Operation::Or,
15
15
  range: Operation::Range}
16
16
  end
17
-
18
- # Dynamically create modules and classes within the `Feature` module based on
19
- # the directory structure of `features`.
20
- #
21
- # For example if the `features` directory has the structure:
22
- #
23
- # features
24
- # ├── thing
25
- # | ├── one.yml
26
- # | └── two.yml
27
- # └── test.yml
28
- #
29
- # `Feature::Test`, `Feature::Thing::One`, `Feature::Thing::Two` would be
30
- # available by default.
31
- #
32
- # TODO: Make this configurable.
33
- if File.directory?("features")
34
- Find.find("features") do |path|
35
- if path.match(/\.ya?ml\Z/)
36
- *directories, filename = path.chomp(File.extname(path)).split("/")
37
-
38
- previous = Feature
39
- directories[1..-1].each do |directory|
40
- module_name = directory.split("_").map(&:capitalize).join.to_sym
41
- previous = begin
42
- previous.const_get(module_name)
43
- rescue NameError
44
- previous.const_set(module_name, Module.new)
45
- end
46
- end
47
-
48
- cls = Class.new(Feature::Base) do |c|
49
- c.const_set(:PERMISSIONS, Feature::Permissions.new(path))
50
- end
51
-
52
- previous.const_set(filename.split("_").map(&:capitalize).join.to_sym, cls)
53
- end
54
- end
55
- end
@@ -3,7 +3,11 @@ module Feature
3
3
  class And
4
4
  def self.call(entity, attr_name, expected)
5
5
  expected.all? do |operation, value|
6
- OPERATIONS[operation.to_sym].call(entity, attr_name, value)
6
+ if OPERATIONS.include? operation.to_sym
7
+ OPERATIONS[operation.to_sym].call(entity, attr_name, value)
8
+ else
9
+ Operation::Attribute.call(entity, operation, value)
10
+ end
7
11
  end
8
12
  end
9
13
  end
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,10 @@ require "rspec/its"
2
2
 
3
3
  require "toggles"
4
4
 
5
+ Toggles.configure do |config|
6
+ config.features_dir = "features"
7
+ end
8
+
5
9
  RSpec.configure do |config|
6
10
  config.order = "random"
7
11
  end
@@ -0,0 +1,7 @@
1
+ describe Toggles::Configuration do
2
+ describe "#features_dir" do
3
+ subject { Toggles::configuration.features_dir }
4
+
5
+ it { is_expected.to eq "features" }
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ describe Feature::ComplexAnd do
2
+ specify do
3
+ expect(Feature::ComplexAnd.enabled_for?(data: double(id: 1))).to eq true
4
+ expect(Feature::ComplexAnd.enabled_for?(data: double(id: 2, timestamp: 0))).to eq true
5
+ expect(Feature::ComplexAnd.enabled_for?(data: double(id: 2, timestamp: 20))).to eq false
6
+ end
7
+ end
data/toggles.gemspec CHANGED
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "toggles"
3
- s.version = "0.0.8"
3
+ s.version = "0.1.0"
4
4
  s.authors = ["Andrew Tribone"]
5
5
  s.summary = "YAML backed feature toggles"
6
6
  s.email = "tribone@easypost.com"
7
- s.homepage = ""
7
+ s.homepage = "https://github.com/att14/toggles"
8
8
  s.license = ""
9
9
  s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
10
10
  s.test_files = s.files.grep(/^(spec)\//)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toggles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Tribone
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-25 00:00:00.000000000 Z
11
+ date: 2015-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -119,11 +119,13 @@ files:
119
119
  - Gemfile
120
120
  - Rakefile
121
121
  - features/collection.yml
122
+ - features/complex_and.yml
122
123
  - features/multiple_subjects.yml
123
124
  - features/nested_attributes.yml
124
125
  - features/or_attributes.yml
125
126
  - features/type.yml
126
127
  - lib/toggles.rb
128
+ - lib/toggles/configuration.rb
127
129
  - lib/toggles/feature.rb
128
130
  - lib/toggles/feature/base.rb
129
131
  - lib/toggles/feature/operation.rb
@@ -138,7 +140,9 @@ files:
138
140
  - lib/toggles/feature/permissions.rb
139
141
  - lib/toggles/feature/subject.rb
140
142
  - spec/spec_helper.rb
143
+ - spec/toggles/configuration_spec.rb
141
144
  - spec/toggles/feature/acceptance/collection_spec.rb
145
+ - spec/toggles/feature/acceptance/complex_and_spec.rb
142
146
  - spec/toggles/feature/acceptance/multiple_subjects_spec.rb
143
147
  - spec/toggles/feature/acceptance/nested_attributes_spec.rb
144
148
  - spec/toggles/feature/acceptance/or_attributes_spec.rb
@@ -155,7 +159,7 @@ files:
155
159
  - spec/toggles/feature/permissions_spec.rb
156
160
  - spec/toggles/feature/subject_spec.rb
157
161
  - toggles.gemspec
158
- homepage: ''
162
+ homepage: https://github.com/att14/toggles
159
163
  licenses:
160
164
  - ''
161
165
  metadata: {}
@@ -181,7 +185,9 @@ specification_version: 4
181
185
  summary: YAML backed feature toggles
182
186
  test_files:
183
187
  - spec/spec_helper.rb
188
+ - spec/toggles/configuration_spec.rb
184
189
  - spec/toggles/feature/acceptance/collection_spec.rb
190
+ - spec/toggles/feature/acceptance/complex_and_spec.rb
185
191
  - spec/toggles/feature/acceptance/multiple_subjects_spec.rb
186
192
  - spec/toggles/feature/acceptance/nested_attributes_spec.rb
187
193
  - spec/toggles/feature/acceptance/or_attributes_spec.rb