this_feature 0.8.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ class ThisFeature
5
5
  class SplitIo < Base
6
6
  # Used as the context key when none is given. This arg is required by
7
7
  # Split, but it's nice not to have to pass it when the context is empty.
8
- EMPTY_CONTEXT = 'undefined_key'
8
+ EMPTY_CONTEXT = 'undefined_key'.freeze
9
9
 
10
10
  def initialize(client: nil, context_key_method: nil)
11
11
  @client = client || default_split_client
@@ -30,6 +30,14 @@ class ThisFeature
30
30
  treatment(flag_name, context: context, data: data, record: record).eql?('off')
31
31
  end
32
32
 
33
+ def treatment_value(flag_name, context: EMPTY_CONTEXT, data: {}, record: nil)
34
+ treatment_with_config(flag_name, context: context, data: data, record: record)[:treatment]
35
+ end
36
+
37
+ def treatment_config(flag_name, context: EMPTY_CONTEXT, data: {}, record: nil)
38
+ treatment_with_config(flag_name, context: context, data: data, record: record)[:config]
39
+ end
40
+
33
41
  private
34
42
 
35
43
  attr_reader :client, :context_key_method
@@ -39,6 +47,11 @@ class ThisFeature
39
47
  client.get_treatment(context_key(context), flag_name, base_data.merge(data))
40
48
  end
41
49
 
50
+ def treatment_with_config(flag_name, context: EMPTY_CONTEXT, data: {}, record: nil)
51
+ base_data = record ? ThisFeature.base_data_lambda.call(record) : {}
52
+ client.get_treatment_with_config(context_key(context), flag_name, base_data.merge(data))
53
+ end
54
+
42
55
  def context_key(context)
43
56
  return EMPTY_CONTEXT if context.nil? || context.eql?(EMPTY_CONTEXT)
44
57
  return context.send(context_key_method) unless context_key_method.nil?
@@ -1,5 +1,5 @@
1
- require_relative './adapters/base.rb'
2
- require_relative './adapters/memory.rb'
1
+ require_relative './adapters/base'
2
+ require_relative './adapters/memory'
3
3
 
4
4
  class ThisFeature
5
5
  module Adapters
@@ -7,10 +7,10 @@ class ThisFeature
7
7
  end
8
8
 
9
9
  def validate_adapters!
10
- raise(NoAdaptersError.new) unless adapters.any?
10
+ raise NoAdaptersError unless adapters.any?
11
11
 
12
12
  adapters.each do |adapter|
13
- raise BadAdapterError.new(adapter) unless adapter.class < Adapters::Base
13
+ raise BadAdapterError, adapter unless adapter.class < Adapters::Base
14
14
  end
15
15
  end
16
16
 
@@ -27,7 +27,7 @@ class ThisFeature
27
27
  end
28
28
 
29
29
  def base_data_lambda
30
- @base_data_lambda ||= -> (record) { {} }
30
+ @base_data_lambda ||= ->(_record) { {} }
31
31
  end
32
32
  end
33
33
  end
@@ -1,10 +1,9 @@
1
1
  class ThisFeature
2
-
3
2
  class Error < StandardError; end
4
3
 
5
4
  class UnimplementedError < Error
6
5
  def initialize(adapter_instance, fn_name)
7
- super("class #{adapter_instance.class.name} doesnt implement method .#{fn_name}")
6
+ super("class #{adapter_instance.class.name} doesn't implement method .#{fn_name}")
8
7
  end
9
8
  end
10
9
 
@@ -16,8 +15,7 @@ class ThisFeature
16
15
 
17
16
  class NoAdaptersError < Error
18
17
  def initialize
19
- super("No adapters configured.")
18
+ super('No adapters configured.')
20
19
  end
21
20
  end
22
-
23
21
  end
@@ -21,5 +21,13 @@ class ThisFeature
21
21
  def control?
22
22
  adapter.control?(flag_name, context: context, data: data, record: record)
23
23
  end
24
+
25
+ def treatment_value
26
+ adapter.treatment_value(flag_name, context: context, data: data, record: record)
27
+ end
28
+
29
+ def treatment_config
30
+ adapter.treatment_config(flag_name, context: context, data: data, record: record)
31
+ end
24
32
  end
25
33
  end
@@ -1,3 +1,3 @@
1
1
  class ThisFeature
2
- VERSION = "0.8.0"
2
+ VERSION = '0.10.0'.freeze
3
3
  end
@@ -1,24 +1,30 @@
1
- # encoding: utf-8
2
-
3
- $:.unshift File.expand_path('../lib', __FILE__)
1
+ $LOAD_PATH.unshift File.expand_path('lib', __dir__)
4
2
 
5
3
  require 'this_feature/version'
6
4
 
7
- Gem::Specification.new do |s|
8
- s.name = 'this_feature-adapters-flipper'
9
- s.version = ThisFeature::VERSION
10
- s.authors = ['Max Pleaner']
11
- s.email = ['maxpleaner@gmail.com']
12
- s.homepage = 'http://hover.to'
13
- s.licenses = ['MIT']
14
- s.summary = '[summary]'
15
- s.description = '[description]'
16
-
17
- s.files = Dir.glob('{bin/*,lib/**/*,[A-Z]*}')
18
- s.platform = Gem::Platform::RUBY
19
- s.require_paths = ['lib']
20
-
21
- s.add_runtime_dependency "this_feature"
22
- s.add_runtime_dependency "flipper", "~> 0.16"
23
- s.add_runtime_dependency "flipper-active_record", "~> 0.16"
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'this_feature-adapters-flipper'
7
+ spec.version = ThisFeature::VERSION
8
+
9
+ spec.required_ruby_version = '>= 3.2'
10
+
11
+ spec.authors = ['Max Pleaner', 'Matt Fong']
12
+ spec.email = ['maxpleaner@gmail.com', 'matthewjf@gmail.com']
13
+
14
+ spec.licenses = ['MIT']
15
+ spec.summary = 'A ThisFeature adapter to Flipper'
16
+ spec.description = ''
17
+ spec.homepage = 'https://github.com/hoverinc/this_feature'
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = spec.homepage
21
+ spec.metadata['rubygems_mfa_required'] = 'true'
22
+
23
+ spec.files = Dir.glob('{bin/*,lib/**/*,[A-Z]*}')
24
+ spec.platform = Gem::Platform::RUBY
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_runtime_dependency 'flipper'
28
+ spec.add_runtime_dependency 'flipper-active_record'
29
+ spec.add_runtime_dependency 'this_feature'
24
30
  end
@@ -1,23 +1,29 @@
1
- # encoding: utf-8
2
-
3
- $:.unshift File.expand_path('../lib', __FILE__)
1
+ $LOAD_PATH.unshift File.expand_path('lib', __dir__)
4
2
 
5
3
  require 'this_feature/version'
6
4
 
7
- Gem::Specification.new do |s|
8
- s.name = 'this_feature-adapters-split_io'
9
- s.version = ThisFeature::VERSION
10
- s.authors = ['Max Pleaner', 'Matt Fong']
11
- s.email = ['maxpleaner@gmail.com', 'matthewjf@gmail.com']
12
- s.homepage = 'http://hover.to'
13
- s.licenses = ['MIT']
14
- s.summary = '[summary]'
15
- s.description = '[description]'
16
-
17
- s.files = Dir.glob('{bin/*,lib/**/*,[A-Z]*}')
18
- s.platform = Gem::Platform::RUBY
19
- s.require_paths = ['lib']
20
-
21
- s.add_runtime_dependency "this_feature"
22
- s.add_runtime_dependency "splitclient-rb"
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'this_feature-adapters-split_io'
7
+ spec.version = ThisFeature::VERSION
8
+
9
+ spec.required_ruby_version = '>= 3.2'
10
+
11
+ spec.authors = ['Max Pleaner', 'Matt Fong']
12
+ spec.email = ['maxpleaner@gmail.com', 'matthewjf@gmail.com']
13
+
14
+ spec.licenses = ['MIT']
15
+ spec.summary = 'A ThisFeature adapter to Split.io'
16
+ spec.description = ''
17
+ spec.homepage = 'https://github.com/hoverinc/this_feature'
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = spec.homepage
21
+ spec.metadata['rubygems_mfa_required'] = 'true'
22
+
23
+ spec.files = Dir.glob('{bin/*,lib/**/*,[A-Z]*}')
24
+ spec.platform = Gem::Platform::RUBY
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_runtime_dependency 'splitclient-rb'
28
+ spec.add_runtime_dependency 'this_feature'
23
29
  end
data/this_feature.gemspec CHANGED
@@ -1,34 +1,38 @@
1
- lib = File.expand_path("lib", __dir__)
1
+ lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "this_feature/version"
3
+ require 'this_feature/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "this_feature"
7
- spec.version = ThisFeature::VERSION
8
- spec.authors = ["Max Pleaner"]
9
- spec.email = ["max.pleaner@hover.to"]
6
+ spec.name = 'this_feature'
7
+ spec.version = ThisFeature::VERSION
10
8
 
11
- spec.summary = %q{Feature flag control}
12
- spec.description = spec.summary
13
- spec.homepage = "https://github.com/hoverinc/this_feature"
9
+ spec.required_ruby_version = '>= 3.2'
14
10
 
15
- spec.metadata["homepage_uri"] = spec.homepage
16
- spec.metadata["source_code_uri"] = spec.homepage
11
+ contributors = {
12
+ 'Max Pleaner' => 'max.pleaner@hover.to',
13
+ 'Matt Fong' => 'matt.fong@hover.to',
14
+ 'Shane Becker' => 'shane.becker@hover.to',
15
+ 'Daniel Deutsch' => 'daniel.deutsch@hover.to'
16
+ }
17
+ spec.authors = contributors.keys
18
+ spec.email = contributors.values
19
+
20
+ spec.licenses = ['MIT']
21
+ spec.summary = 'A common interface to interact with many feature flag providers'
22
+ spec.description = ''
23
+ spec.homepage = 'https://github.com/hoverinc/this_feature'
24
+
25
+ spec.metadata['homepage_uri'] = spec.homepage
26
+ spec.metadata['source_code_uri'] = spec.homepage
27
+ spec.metadata['rubygems_mfa_required'] = 'true'
17
28
 
18
29
  # Specify which files should be added to the gem when it is released.
19
30
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
32
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
33
  end
23
- spec.bindir = "exe"
24
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
- spec.require_paths = ["lib"]
26
34
 
27
- spec.add_development_dependency "bundler", "~> 2.0"
28
- spec.add_development_dependency "pry-byebug"
29
- spec.add_development_dependency "rake", "~> 13.0"
30
- spec.add_development_dependency "rspec", "~> 3.0"
31
- spec.add_development_dependency "sqlite3"
32
- spec.add_development_dependency "database_cleaner-active_record"
33
- spec.add_development_dependency "gem-release"
35
+ spec.bindir = 'exe'
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ['lib']
34
38
  end
metadata CHANGED
@@ -1,123 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: this_feature
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Pleaner
8
+ - Matt Fong
9
+ - Shane Becker
10
+ - Daniel Deutsch
8
11
  autorequire:
9
12
  bindir: exe
10
13
  cert_chain: []
11
- date: 2023-01-04 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2.0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '2.0'
27
- - !ruby/object:Gem::Dependency
28
- name: pry-byebug
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '13.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '13.0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '3.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '3.0'
69
- - !ruby/object:Gem::Dependency
70
- name: sqlite3
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: database_cleaner-active_record
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: gem-release
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- description: Feature flag control
14
+ date: 2023-10-16 00:00:00.000000000 Z
15
+ dependencies: []
16
+ description: ''
112
17
  email:
113
18
  - max.pleaner@hover.to
19
+ - matt.fong@hover.to
20
+ - shane.becker@hover.to
21
+ - daniel.deutsch@hover.to
114
22
  executables: []
115
23
  extensions: []
116
24
  extra_rdoc_files: []
117
25
  files:
26
+ - ".github/workflows/linter-rubocop.yml"
118
27
  - ".github/workflows/test.yml"
119
28
  - ".gitignore"
120
29
  - ".rspec"
30
+ - ".rubocop.yml"
31
+ - ".rubocop_todo.yml"
32
+ - ".ruby-version"
121
33
  - ".travis.yml"
122
34
  - CODE_OF_CONDUCT.md
123
35
  - Gemfile
@@ -127,7 +39,6 @@ files:
127
39
  - Rakefile
128
40
  - bin/console
129
41
  - bin/setup
130
- - docs/flipper.html
131
42
  - docs/flipper.md
132
43
  - docs/memory.md
133
44
  - docs/splitio.md
@@ -146,10 +57,12 @@ files:
146
57
  - this_feature-adapters-split_io.gemspec
147
58
  - this_feature.gemspec
148
59
  homepage: https://github.com/hoverinc/this_feature
149
- licenses: []
60
+ licenses:
61
+ - MIT
150
62
  metadata:
151
63
  homepage_uri: https://github.com/hoverinc/this_feature
152
64
  source_code_uri: https://github.com/hoverinc/this_feature
65
+ rubygems_mfa_required: 'true'
153
66
  post_install_message:
154
67
  rdoc_options: []
155
68
  require_paths:
@@ -158,15 +71,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
71
  requirements:
159
72
  - - ">="
160
73
  - !ruby/object:Gem::Version
161
- version: '0'
74
+ version: '3.2'
162
75
  required_rubygems_version: !ruby/object:Gem::Requirement
163
76
  requirements:
164
77
  - - ">="
165
78
  - !ruby/object:Gem::Version
166
79
  version: '0'
167
80
  requirements: []
168
- rubygems_version: 3.0.3
81
+ rubygems_version: 3.4.10
169
82
  signing_key:
170
83
  specification_version: 4
171
- summary: Feature flag control
84
+ summary: A common interface to interact with many feature flag providers
172
85
  test_files: []