Skip to content

Commit 317f7b7

Browse files
authored
Refactor feature and group management to include descriptions (#19)
1 parent 2996458 commit 317f7b7

File tree

14 files changed

+230
-89
lines changed

14 files changed

+230
-89
lines changed

examples/usual/example1/d_feature.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ class DFeature < Usual::Example1::Base
1111
condition ->(resources:) { resources.record.id == "123" }
1212

1313
# full » :usual_example_1_d_i
14+
feature :i, description: "D I feature"
15+
1416
# full » :usual_example_1_d_ii
17+
feature :ii, description: "D II feature"
18+
1519
# full » :usual_example_1_d_iii
16-
features(
17-
:i,
18-
:ii,
19-
:iii
20-
)
20+
feature :iii, description: "D III feature"
2121
end
2222
end
2323
end

examples/usual/example1/e_feature.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ class EFeature < Usual::Example1::Base
1010
condition ->(resources:) { resources.record.id == "123" }
1111

1212
# full » :usual_example_1_e_i
13+
feature :i, description: "E I feature"
14+
1315
# full » :usual_example_1_e_ii
16+
feature :ii, description: "E II feature"
17+
1418
# full » :usual_example_1_e_iii
15-
features(
16-
:i,
17-
:ii,
18-
:iii
19-
)
19+
feature :iii, description: "E III feature"
2020
end
2121
end
2222
end

examples/usual/example1/main_feature.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@ class MainFeature < Usual::Example1::Base
1414
condition ->(resources:) { resources.record.id == "123" }
1515

1616
# full » :usual_example_1_a
17+
feature :a, description: "A feature"
18+
1719
# full » :usual_example_1_b
20+
feature :b, description: "B feature"
21+
1822
# full » :usual_example_1_c
19-
features(
20-
:a,
21-
:b,
22-
:c
23-
)
24-
25-
groups(
26-
Usual::Example1::DFeature,
27-
Usual::Example1::EFeature
28-
)
23+
feature :c, description: "C feature"
24+
25+
group Usual::Example1::DFeature, description: "D feature group"
26+
group Usual::Example1::EFeature, description: "E feature group"
2927
end
3028
end
3129
end

lib/featury/actions/service/factory.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def features_are_true
6565
[resource.name, inputs.public_send(resource.name)]
6666
end
6767

68-
inputs.action.block.call(features: inputs.collection_of_features.full_names, **options)
68+
inputs.action.block.call(features: inputs.collection_of_features.names, **options)
6969
end
7070

7171
def groups_are_true
@@ -74,7 +74,7 @@ def groups_are_true
7474
end
7575

7676
inputs.collection_of_groups.all? do |group|
77-
group.group.public_send(inputs.action.name, **arguments)
77+
group.group_class.public_send(inputs.action.name, **arguments)
7878
end
7979
end
8080
end

lib/featury/callbacks/workspace.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ def call!(action:, collection_of_callbacks:, collection_of_features:, **) # rubo
99
Featury::Callbacks::Service.call!(
1010
action: action.name,
1111
callbacks: collection_of_callbacks.before,
12-
features: collection_of_features.full_names
12+
features: collection_of_features.names
1313
)
1414

1515
result = super
1616

1717
Featury::Callbacks::Service.call!(
1818
action: action.name,
1919
callbacks: collection_of_callbacks.after,
20-
features: collection_of_features.full_names
20+
features: collection_of_features.names
2121
)
2222

2323
result

lib/featury/features/collection.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ module Featury
44
module Features
55
class Collection
66
extend Forwardable
7-
def_delegators :@collection, :<<, :each, :map, :merge
7+
def_delegators :@collection, :<<, :each, :map, :merge, :to_a
88

99
def initialize(collection = Set.new)
1010
@collection = collection
1111
end
1212

13-
def full_names
14-
map(&:full_name)
13+
def names
14+
map(&:name)
1515
end
1616
end
1717
end

lib/featury/features/dsl.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,22 @@ def prefix(prefix)
2020
self.feature_prefix = prefix
2121
end
2222

23+
# DEPRECATED: Need to use the `feature` method instead of `features`.
2324
def features(*names)
25+
Kernel.warn "DEPRECATION WARNING: " \
26+
"Method `features` is deprecated; " \
27+
"use `feature` instead. " \
28+
"It will be removed in one of the next releases."
29+
2430
names.each do |name|
25-
collection_of_features << Feature.new(feature_prefix, name)
31+
collection_of_features << Feature.new(prefix: feature_prefix, name:, description: nil)
2632
end
2733
end
2834

35+
def feature(name, description: nil)
36+
collection_of_features << Feature.new(prefix: feature_prefix, name:, description:)
37+
end
38+
2939
def feature_prefix=(value)
3040
@feature_prefix = value
3141
end

lib/featury/features/feature.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
module Featury
44
module Features
55
class Feature
6-
def initialize(prefix, name)
7-
@prefix = prefix
8-
@name = name
9-
end
6+
attr_reader :name,
7+
:description
108

11-
def full_name
12-
:"#{@prefix}_#{@name}"
9+
def initialize(prefix:, name:, description:)
10+
@name = :"#{prefix}_#{name}"
11+
@description = description
1312
end
1413
end
1514
end

lib/featury/groups/collection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Featury
44
module Groups
55
class Collection
66
extend Forwardable
7-
def_delegators :@collection, :<<, :each, :map, :filter, :to_h, :merge, :all?
7+
def_delegators :@collection, :<<, :each, :map, :flat_map, :filter, :to_h, :merge, :to_a, :all?
88

99
def initialize(collection = Set.new)
1010
@collection = collection

lib/featury/groups/dsl.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,22 @@ def inherited(child)
1616

1717
private
1818

19+
# DEPRECATED: Need to use the `group` method instead of `groups`.
1920
def groups(*groups)
21+
Kernel.warn "DEPRECATION WARNING: " \
22+
"Method `groups` is deprecated; " \
23+
"use `group` instead. " \
24+
"It will be removed in one of the next releases."
25+
2026
groups.each do |group|
21-
collection_of_groups << Group.new(group)
27+
collection_of_groups << Group.new(group:, description: nil)
2228
end
2329
end
2430

31+
def group(group, description: nil)
32+
collection_of_groups << Group.new(group:, description:)
33+
end
34+
2535
def collection_of_groups
2636
@collection_of_groups ||= Collection.new
2737
end

0 commit comments

Comments
 (0)