featury 1.0.0.rc13 → 1.0.0.rc14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97cc910762d980a170b075f98d2b5fe4cff87af8680477a06805fd31f0f9576b
4
- data.tar.gz: 14ebb9a2d462b8414d5291a64b1a8d7c4b3957a3ad3669ebd88fc39c821c5ec4
3
+ metadata.gz: e96956d416b000864c67950857203f8b5684e6340b5f73bce937415ec19b4847
4
+ data.tar.gz: b55c10a5650293385194cccf8b18bf954bccecac287b244b80801a6d5ec7b587
5
5
  SHA512:
6
- metadata.gz: 6ddf5182c50a1476a46d5ab336a0cb11baf3e0c9c72d27c71e51b5b5b1134376972aede1c3b0d334f3dc5b621096695ca45cc9e058b14a31816c3e11b946bf57
7
- data.tar.gz: 8584f3fec8b9bdf944923754fe27ffcb54ac3b13b9ed5e4393449ce6c2505b6760418f3c84651e55ce80a9c276e95a8c8df9d8f702b2fb039051973d48036148
6
+ metadata.gz: 4c3e6a1e487b2987c0d8ac8f9177be1fe63191b6f2522b9d355db792c03cf40ba378b5b9d0c58ac90c439e1c587ca3e384da99287dd1f292b7dbebf2250b1bf4
7
+ data.tar.gz: '0193892e10d804f0edde8bbc201eb8c8c42de5209d54d23f2f990da1a571aa83e9efcbbf0a99c7a4bdd052d25cb3968d394e368d52d1b713340cbaf62be7bcd2'
data/README.md CHANGED
@@ -26,7 +26,7 @@ gem "featury"
26
26
  #### Basic class for your features
27
27
 
28
28
  For instance, assume that you are utilizing Flipper for managing features.
29
- In such scenario, the base class could potentially be structured as follows:
29
+ In such a scenario, the base class could potentially be structured as follows:
30
30
 
31
31
  ```ruby
32
32
  class ApplicationFeature < Featury::Base
@@ -45,19 +45,27 @@ class ApplicationFeature < Featury::Base
45
45
  action :disable do |features:, **options|
46
46
  features.all? { |feature| Flipper.disable(feature, *options.values) }
47
47
  end
48
+
49
+ before do |action:, features:|
50
+ Slack::API::Notify.call!(action:, features:)
51
+ end
52
+
53
+ after do |action:, features:|
54
+ Slack::API::Notify.call!(action:, features:)
55
+ end
48
56
  end
49
57
  ```
50
58
 
51
59
  #### Features of your project
52
60
 
53
61
  ```ruby
54
- class UserFeature::Onboarding < ApplicationFeature
62
+ class User::OnboardingFeature < ApplicationFeature
63
+ prefix :user_onboarding
64
+
55
65
  resource :user, type: User
56
66
 
57
67
  condition ->(resources:) { resources.user.onboarding_awaiting? }
58
68
 
59
- prefix :user_onboarding
60
-
61
69
  features :passage # => :user_onboarding_passage
62
70
 
63
71
  groups BillingFeature,
@@ -104,16 +112,16 @@ Each of these actions will be applied to every feature flag.
104
112
  Subsequently, the outcome of these actions will be contingent upon the combined results of all feature flags.
105
113
 
106
114
  ```ruby
107
- UserFeature::Onboarding.enabled?(user:) # => true
108
- UserFeature::Onboarding.disabled?(user:) # => false
109
- UserFeature::Onboarding.enable(user:) # => true
110
- UserFeature::Onboarding.disable(user:) # => true
115
+ User::OnboardingFeature.enabled?(user:) # => true
116
+ User::OnboardingFeature.disabled?(user:) # => false
117
+ User::OnboardingFeature.enable(user:) # => true
118
+ User::OnboardingFeature.disable(user:) # => true
111
119
  ```
112
120
 
113
121
  You can also utilize the `with` method to pass necessary arguments.
114
122
 
115
123
  ```ruby
116
- feature = UserFeature::Onboarding.with(user:)
124
+ feature = User::OnboardingFeature.with(user:)
117
125
 
118
126
  feature.enabled? # => true
119
127
  feature.disabled? # => false
@@ -3,10 +3,11 @@
3
3
  module Featury
4
4
  module Callbacks
5
5
  class Callback
6
- attr_reader :block
6
+ attr_reader :desired_actions, :block
7
7
 
8
- def initialize(stage, block:)
8
+ def initialize(stage:, desired_actions:, block:)
9
9
  @stage = stage.to_sym
10
+ @desired_actions = desired_actions
10
11
  @block = block
11
12
  end
12
13
 
@@ -10,12 +10,21 @@ module Featury
10
10
  @collection = collection
11
11
  end
12
12
 
13
+ def desired_actions(include:)
14
+ Collection.new(
15
+ filter do |callback|
16
+ callback.desired_actions.blank? ||
17
+ callback.desired_actions.include?(include)
18
+ end
19
+ )
20
+ end
21
+
13
22
  def before
14
- @before ||= Collection.new(filter(&:before?))
23
+ Collection.new(filter(&:before?))
15
24
  end
16
25
 
17
26
  def after
18
- @after ||= Collection.new(filter(&:after?))
27
+ Collection.new(filter(&:after?))
19
28
  end
20
29
  end
21
30
  end
@@ -17,17 +17,19 @@ module Featury
17
17
 
18
18
  private
19
19
 
20
- def before
20
+ def before(*actions)
21
21
  collection_of_callbacks << Callback.new(
22
- :before,
23
- block: ->(action:, features:) { yield(action:, features:) }
22
+ stage: :before,
23
+ desired_actions: actions,
24
+ block: ->(**arguments) { yield(**arguments) }
24
25
  )
25
26
  end
26
27
 
27
- def after
28
+ def after(*actions)
28
29
  collection_of_callbacks << Callback.new(
29
- :after,
30
- block: ->(action:, features:) { yield(action:, features:) }
30
+ stage: :after,
31
+ desired_actions: actions,
32
+ block: ->(**arguments) { yield(**arguments) }
31
33
  )
32
34
  end
33
35
 
@@ -8,13 +8,13 @@ module Featury
8
8
  end
9
9
 
10
10
  def initialize(action:, callbacks:, features:)
11
- @callbacks = callbacks
12
11
  @action = action
12
+ @callbacks = callbacks
13
13
  @features = features
14
14
  end
15
15
 
16
16
  def call!
17
- @callbacks.each do |callback|
17
+ @callbacks.desired_actions(include: @action).each do |callback|
18
18
  callback.block.call(action: @action, features: @features)
19
19
  end
20
20
  end
@@ -5,7 +5,7 @@ module Featury
5
5
  MAJOR = 1
6
6
  MINOR = 0
7
7
  PATCH = 0
8
- PRE = "rc13"
8
+ PRE = "rc14"
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
11
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: featury
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc13
4
+ version: 1.0.0.rc14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov