flipper-cloud 0.11.0.beta7 → 0.11.0.beta8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/examples/cloud/cached_in_memory.rb +29 -0
- data/lib/flipper/cloud/configuration.rb +85 -0
- data/lib/flipper/cloud.rb +7 -34
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/cloud/configuration_spec.rb +58 -0
- data/spec/flipper/cloud_spec.rb +4 -3
- metadata +8 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3a3c2f7161eea7fbe9301cb071628fdba2701762
|
|
4
|
+
data.tar.gz: 21cb58e7ccb42782a6e27c30041921e133d4ece4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2e1c85a80adbdf9ce82f0e2a7734a5529502256e3c81a8774a635ea62e88f538bbe6c7e74721422953f9dd70563148f296fdd0d05300deed81727fa22a493ad1
|
|
7
|
+
data.tar.gz: 41ef7a54f326005f4c88c1d08a54ca7a40a724d0741246b64a3a97e50f6e87f47e67c68d63e1107466ce95eb3ebdeca67ee486bc6215fad560a3a1e415df5b38
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require File.expand_path('../../example_setup', __FILE__)
|
|
2
|
+
|
|
3
|
+
require 'flipper/cloud'
|
|
4
|
+
require 'flipper/adapters/cache_store'
|
|
5
|
+
require 'active_support/cache'
|
|
6
|
+
require 'active_support/cache/memory_store'
|
|
7
|
+
|
|
8
|
+
token = ENV.fetch("TOKEN") { abort "TOKEN environment variable not set." }
|
|
9
|
+
feature_name = ENV.fetch("FEATURE") { "testing" }.to_sym
|
|
10
|
+
|
|
11
|
+
Flipper.configure do |config|
|
|
12
|
+
config.default do
|
|
13
|
+
Flipper::Cloud.new(token) do |cloud|
|
|
14
|
+
cloud.debug_output = STDOUT
|
|
15
|
+
cloud.adapter do |adapter|
|
|
16
|
+
Flipper::Adapters::CacheStore.new(adapter,
|
|
17
|
+
ActiveSupport::Cache::MemoryStore.new, {expires_in: 5.seconds})
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
loop do
|
|
24
|
+
# Should only print out http call every 5 seconds
|
|
25
|
+
p Flipper.enabled?(feature_name)
|
|
26
|
+
puts "\n\n"
|
|
27
|
+
|
|
28
|
+
sleep 1
|
|
29
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require "flipper/adapters/http"
|
|
2
|
+
require "flipper/instrumenters/noop"
|
|
3
|
+
|
|
4
|
+
module Flipper
|
|
5
|
+
module Cloud
|
|
6
|
+
class Configuration
|
|
7
|
+
# The default url should be the one, the only, the website.
|
|
8
|
+
DEFAULT_URL = "https://www.featureflipper.com/adapter".freeze
|
|
9
|
+
|
|
10
|
+
# Public: The token corresponding to an environment on featureflipper.com.
|
|
11
|
+
attr_accessor :token
|
|
12
|
+
|
|
13
|
+
# Public: The url for http adapter (default: Flipper::Cloud::DEFAULT_URL).
|
|
14
|
+
# Really should only be customized for development work. Feel free
|
|
15
|
+
# to forget you ever saw this.
|
|
16
|
+
attr_reader :url
|
|
17
|
+
|
|
18
|
+
# Public: net/http read timeout for all http requests (default: 5).
|
|
19
|
+
attr_accessor :read_timeout
|
|
20
|
+
|
|
21
|
+
# Public: net/http open timeout for all http requests (default: 5).
|
|
22
|
+
attr_accessor :open_timeout
|
|
23
|
+
|
|
24
|
+
# Public: IO stream to send debug output too. Off by default.
|
|
25
|
+
#
|
|
26
|
+
# # for example, this would send all http request information to STDOUT
|
|
27
|
+
# configuration = Flipper::Cloud::Configuration.new
|
|
28
|
+
# configuration.debug_output = STDOUT
|
|
29
|
+
attr_accessor :debug_output
|
|
30
|
+
|
|
31
|
+
# Public: Instrumenter to use for the Flipper instance returned by
|
|
32
|
+
# Flipper::Cloud.new (default: Flipper::Instrumenters::Noop).
|
|
33
|
+
#
|
|
34
|
+
# # for example, to use active support notifications you could do:
|
|
35
|
+
# configuration = Flipper::Cloud::Configuration.new
|
|
36
|
+
# configuration.instrumenter = ActiveSupport::Notifications
|
|
37
|
+
attr_accessor :instrumenter
|
|
38
|
+
|
|
39
|
+
def initialize(options = {})
|
|
40
|
+
@token = options.fetch(:token)
|
|
41
|
+
@instrumenter = options.fetch(:instrumenter, Instrumenters::Noop)
|
|
42
|
+
@read_timeout = options.fetch(:read_timeout, 5)
|
|
43
|
+
@open_timeout = options.fetch(:open_timeout, 5)
|
|
44
|
+
@debug_output = options[:debug_output]
|
|
45
|
+
@adapter_block = ->(adapter) { adapter }
|
|
46
|
+
|
|
47
|
+
self.url = options.fetch(:url, DEFAULT_URL)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Public: Read or customize the http adapter. Calling without a block will
|
|
51
|
+
# perform a read. Calling with a block yields the http_adapter
|
|
52
|
+
# for customization.
|
|
53
|
+
#
|
|
54
|
+
# # for example, to instrument the http calls, you can wrap the http
|
|
55
|
+
# # adapter with the intsrumented adapter
|
|
56
|
+
# configuration = Flipper::Cloud::Configuration.new
|
|
57
|
+
# configuration.adapter do |adapter|
|
|
58
|
+
# Flipper::Adapters::Instrumented.new(adapter)
|
|
59
|
+
# end
|
|
60
|
+
#
|
|
61
|
+
def adapter(&block)
|
|
62
|
+
if block_given?
|
|
63
|
+
@adapter_block = block
|
|
64
|
+
else
|
|
65
|
+
@adapter_block.call(http_adapter)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Public: Set url and uri for the http adapter.
|
|
70
|
+
attr_writer :url
|
|
71
|
+
|
|
72
|
+
private
|
|
73
|
+
|
|
74
|
+
def http_adapter
|
|
75
|
+
Flipper::Adapters::Http.new(url: @url,
|
|
76
|
+
read_timeout: @read_timeout,
|
|
77
|
+
open_timeout: @open_timeout,
|
|
78
|
+
debug_output: @debug_output,
|
|
79
|
+
headers: {
|
|
80
|
+
"Feature-Flipper-Token" => @token,
|
|
81
|
+
})
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
data/lib/flipper/cloud.rb
CHANGED
|
@@ -1,45 +1,18 @@
|
|
|
1
|
-
require "flipper/
|
|
2
|
-
require "flipper/instrumenters/noop"
|
|
1
|
+
require "flipper/cloud/configuration"
|
|
3
2
|
|
|
4
3
|
module Flipper
|
|
5
4
|
module Cloud
|
|
6
|
-
# The default adapter wrapper which doesn't wrap at all.
|
|
7
|
-
DEFAULT_ADAPTER_WRAPPER_BLOCK = ->(adapter) { adapter }
|
|
8
|
-
|
|
9
|
-
# The default url should be the one, the only, the website.
|
|
10
|
-
DEFAULT_URL = "https://www.featureflipper.com/adapter".freeze
|
|
11
|
-
|
|
12
5
|
# Public: Returns a new Flipper instance with an http adapter correctly
|
|
13
6
|
# configured for flipper cloud.
|
|
14
7
|
#
|
|
15
8
|
# token - The String token for the environment from the website.
|
|
16
|
-
# options - The Hash of options.
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
# receive an adapter and return an adapter.
|
|
20
|
-
# Allows you to wrap the http adapter with
|
|
21
|
-
# other adapters to make instrumentation and
|
|
22
|
-
# caching easy.
|
|
23
|
-
# # :instrumenter - The optional instrumenter to use for the
|
|
24
|
-
# Flipper::DSL instance (defaults to Noop).
|
|
9
|
+
# options - The Hash of options. See Flipper::Cloud::Configuration.
|
|
10
|
+
# block - The block that configuration will be yielded to allowing you to
|
|
11
|
+
# customize this cloud instance and its adapter.
|
|
25
12
|
def self.new(token, options = {})
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
headers: {
|
|
30
|
-
"Feature-Flipper-Token" => token,
|
|
31
|
-
},
|
|
32
|
-
read_timeout: options[:read_timeout],
|
|
33
|
-
open_timeout: options[:open_timeout],
|
|
34
|
-
debug_output: options[:debug_output],
|
|
35
|
-
}
|
|
36
|
-
adapter = Flipper::Adapters::Http.new(http_options)
|
|
37
|
-
|
|
38
|
-
adapter_wrapper = options.fetch(:adapter_wrapper, DEFAULT_ADAPTER_WRAPPER_BLOCK)
|
|
39
|
-
adapter = adapter_wrapper.call(adapter)
|
|
40
|
-
|
|
41
|
-
instrumenter = options.fetch(:instrumenter, Flipper::Instrumenters::Noop)
|
|
42
|
-
Flipper.new(adapter, instrumenter: instrumenter)
|
|
13
|
+
configuration = Configuration.new(options.merge(token: token))
|
|
14
|
+
yield configuration if block_given?
|
|
15
|
+
Flipper.new(configuration.adapter, instrumenter: configuration.instrumenter)
|
|
43
16
|
end
|
|
44
17
|
end
|
|
45
18
|
end
|
data/lib/flipper/version.rb
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'helper'
|
|
2
|
+
require 'flipper/cloud/configuration'
|
|
3
|
+
require 'flipper/adapters/instrumented'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Flipper::Cloud::Configuration do
|
|
6
|
+
let(:required_options) do
|
|
7
|
+
{ token: "asdf" }
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "can set token" do
|
|
11
|
+
instance = described_class.new(required_options)
|
|
12
|
+
expect(instance.token).to eq(required_options[:token])
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "can set instrumenter" do
|
|
16
|
+
instrumenter = Object.new
|
|
17
|
+
instance = described_class.new(required_options.merge(instrumenter: instrumenter))
|
|
18
|
+
expect(instance.instrumenter).to be(instrumenter)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "can set read_timeout" do
|
|
22
|
+
instance = described_class.new(required_options.merge(read_timeout: 5))
|
|
23
|
+
expect(instance.read_timeout).to eq(5)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "can set open_timeout" do
|
|
27
|
+
instance = described_class.new(required_options.merge(open_timeout: 5))
|
|
28
|
+
expect(instance.open_timeout).to eq(5)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "can set debug_output" do
|
|
32
|
+
instance = described_class.new(required_options.merge(debug_output: STDOUT))
|
|
33
|
+
expect(instance.debug_output).to eq(STDOUT)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "defaults adapter block" do
|
|
37
|
+
instance = described_class.new(required_options)
|
|
38
|
+
expect(instance.adapter).to be_instance_of(Flipper::Adapters::Http)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "can override adapter block" do
|
|
42
|
+
instance = described_class.new(required_options)
|
|
43
|
+
instance.adapter do |adapter|
|
|
44
|
+
Flipper::Adapters::Instrumented.new(adapter)
|
|
45
|
+
end
|
|
46
|
+
expect(instance.adapter).to be_instance_of(Flipper::Adapters::Instrumented)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "can override url" do
|
|
50
|
+
options = required_options.merge(url: "http://localhost:5000/adapter")
|
|
51
|
+
instance = described_class.new(options)
|
|
52
|
+
expect(instance.url).to eq("http://localhost:5000/adapter")
|
|
53
|
+
|
|
54
|
+
instance = described_class.new(required_options)
|
|
55
|
+
instance.url = "http://localhost:5000/adapter"
|
|
56
|
+
expect(instance.url).to eq("http://localhost:5000/adapter")
|
|
57
|
+
end
|
|
58
|
+
end
|
data/spec/flipper/cloud_spec.rb
CHANGED
|
@@ -61,10 +61,11 @@ RSpec.describe Flipper::Cloud do
|
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
it 'allows wrapping adapter with another adapter like the instrumenter' do
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
instance = described_class.new('asdf') do |config|
|
|
65
|
+
config.adapter do |adapter|
|
|
66
|
+
Flipper::Adapters::Instrumented.new(adapter)
|
|
67
|
+
end
|
|
66
68
|
end
|
|
67
|
-
instance = described_class.new('asdf', adapter_wrapper: adapter_wrapper)
|
|
68
69
|
# instance.adapter is memoizable adapter instance
|
|
69
70
|
expect(instance.adapter.adapter).to be_instance_of(Flipper::Adapters::Instrumented)
|
|
70
71
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: flipper-cloud
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.11.0.
|
|
4
|
+
version: 0.11.0.beta8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Nunemaker
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-
|
|
11
|
+
date: 2017-10-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: flipper
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 0.11.0.
|
|
19
|
+
version: 0.11.0.beta8
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 0.11.0.
|
|
26
|
+
version: 0.11.0.beta8
|
|
27
27
|
description: FeatureFlipper.com adapter for Flipper
|
|
28
28
|
email:
|
|
29
29
|
- nunemaker@gmail.com
|
|
@@ -32,10 +32,13 @@ extensions: []
|
|
|
32
32
|
extra_rdoc_files: []
|
|
33
33
|
files:
|
|
34
34
|
- examples/cloud/basic.rb
|
|
35
|
+
- examples/cloud/cached_in_memory.rb
|
|
35
36
|
- flipper-cloud.gemspec
|
|
36
37
|
- lib/flipper-cloud.rb
|
|
37
38
|
- lib/flipper/cloud.rb
|
|
39
|
+
- lib/flipper/cloud/configuration.rb
|
|
38
40
|
- lib/flipper/version.rb
|
|
41
|
+
- spec/flipper/cloud/configuration_spec.rb
|
|
39
42
|
- spec/flipper/cloud_spec.rb
|
|
40
43
|
homepage: https://github.com/jnunemaker/flipper
|
|
41
44
|
licenses:
|
|
@@ -62,4 +65,5 @@ signing_key:
|
|
|
62
65
|
specification_version: 4
|
|
63
66
|
summary: FeatureFlipper.com adapter for Flipper
|
|
64
67
|
test_files:
|
|
68
|
+
- spec/flipper/cloud/configuration_spec.rb
|
|
65
69
|
- spec/flipper/cloud_spec.rb
|