unleash-incognia 0.1.0 → 0.2.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
  SHA256:
3
- metadata.gz: 274bb820b751368f97fe5c99fb5640ea819e3e9388cbe7eacd1a76bc80e7d607
4
- data.tar.gz: c994e063522e2f6824afd21b6a657143bf326c980b4ba019954236473ef0198b
3
+ metadata.gz: f1c56a74ce540b6d9aa984bec2c8af0227220f21700af8e40365a2756dae8e47
4
+ data.tar.gz: f0d2bf0e4191dc4b2c029d1e16ab0cd3b309690487292e767fa402f1f7dd556a
5
5
  SHA512:
6
- metadata.gz: 9fc5d9a1aa9a8439baa2e4e9d9291d9a091430ca1d7beddb10a80bcf3ffc4d9d925474f29f43303b762502f83b8c4e76bb3aa6cfbc072a2c1f105055ade37f27
7
- data.tar.gz: 20ac01a6942fcc79d08f1b113aac82e35622b4b9073f3f02014a2af0e866c5877ede1ec3db2cbe2027ecb21008517d903d8f80bcac4fceb9c1e614f7a3a5eaa8
6
+ metadata.gz: 11476cf48a827fe7ff4f76d4091ebdde29761b2fa52fa66d892bb4dbc42ca831a0efb8c94e093e150076ddb46508d4f292d65b827241cf4c65dde8d88e84918d
7
+ data.tar.gz: 3832c9d69f1029e414ccf9d4fddfcce6351acc23673171d35e44bfd0e3b48e95842068a8ad182674d3512d085ec492f560047f229d756a16a8784a10b3970b00
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unleash-incognia (0.1.0)
4
+ unleash-incognia (0.2.0)
5
5
  unleash (~> 3.2)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -24,6 +24,49 @@ Or install it yourself as:
24
24
 
25
25
  You must set up [Unleash Ruby SDK](https://github.com/Unleash/unleash-client-ruby) in order to use these custom strategies.
26
26
 
27
+ ```ruby
28
+ > user = OpenStruct.new(id: 2, email: 'my@mail.com')
29
+ => #<OpenStruct id=2, email="my@mail.com">
30
+
31
+ > Unleash::Incognia::Client.new(user: user).enabled_features
32
+ => ["incognia_feature_1"]
33
+
34
+ > organization = OpenStruct.new(id: 5)
35
+ => #<OpenStruct id=5>
36
+
37
+ > client = Unleash::Incognia::Client.new(user: user, organization: organization)
38
+ => #<Unleash::Incognia::Client:0x000055caf7c7f390 @user=#<OpenStruct id=2, email="my@mail.com">, @organization=#<OpenStruct id=5>>
39
+
40
+ # List enabled features
41
+ > client.enabled_features
42
+ => ["incognia_feature_1", "incognia_feature_2", "incognia_feature_3"]
43
+
44
+ # Ask if some feature is enabled
45
+ > client.feature_enabled?("disabled_feature")
46
+ => false
47
+
48
+ > client.feature_enabled?("incognia_feature_2")
49
+ => true
50
+ ```
51
+
52
+ ### Configuration
53
+
54
+ Whenever you have `Unleash::Client` being instanciated change it to:
55
+
56
+ ```ruby
57
+ Unleash::Incognia.configure do |config|
58
+ config.unleash_client = Unleash::Client.new
59
+ end
60
+ ```
61
+
62
+ Or:
63
+
64
+ ```ruby
65
+ Unleash::Incognia.configuration.unleash_client = Unleash::Client.new
66
+ ```
67
+
68
+ This way, `Unleash::Incognia` client will use proper `Unleash` client.
69
+
27
70
  ## Development
28
71
 
29
72
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,40 @@
1
+ module Unleash
2
+ module Incognia
3
+ class Client
4
+ def initialize(user:, organization: nil)
5
+ @user = user
6
+ @organization = organization
7
+ end
8
+
9
+ def feature_enabled?(name)
10
+ client.is_enabled? name, context
11
+ end
12
+
13
+ def enabled_features
14
+ feature_flags_names = Unleash.toggles.map do |feature_flag|
15
+ feature_flag['name']
16
+ end
17
+
18
+ feature_flags_names.select { |name| feature_enabled?(name) }
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :user, :organization
24
+
25
+ def client
26
+ Incognia.configuration.unleash_client
27
+ end
28
+
29
+ def context
30
+ @context ||= Unleash::Context.new(
31
+ properties: {
32
+ user_id: user.id,
33
+ user_email: user.email,
34
+ organization_id: organization&.id
35
+ }.compact
36
+ )
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ module Unleash
2
+ module Incognia
3
+ class Configuration
4
+ attr_accessor :unleash_client
5
+
6
+ def initialize(**attributes)
7
+ attributes.each do |attribute, value|
8
+ if respond_to?("#{attribute}=")
9
+ method("#{attribute}=").call(value)
10
+ else
11
+ instance_variable_set("@#{attribute}", value)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
1
  module Unleash
2
2
  module Incognia
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -5,6 +5,19 @@ require 'unleash/strategy/member'
5
5
  require 'unleash/strategy/email_domain'
6
6
  require 'unleash/strategy/organization'
7
7
 
8
+ require 'unleash/incognia/configuration'
9
+ require 'unleash/incognia/client'
10
+
8
11
  module Unleash
9
- module Incognia ; end
12
+ module Incognia
13
+ class << self
14
+ def configuration
15
+ @configuration ||= Configuration.new
16
+ end
17
+
18
+ def configure
19
+ yield(configuration)
20
+ end
21
+ end
22
+ end
10
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unleash-incognia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juliana Lucena
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-05 00:00:00.000000000 Z
11
+ date: 2021-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unleash
@@ -42,6 +42,8 @@ files:
42
42
  - bin/console
43
43
  - bin/setup
44
44
  - lib/unleash/incognia.rb
45
+ - lib/unleash/incognia/client.rb
46
+ - lib/unleash/incognia/configuration.rb
45
47
  - lib/unleash/incognia/version.rb
46
48
  - lib/unleash/strategy/email_domain.rb
47
49
  - lib/unleash/strategy/member.rb