slack-ruby-block-kit 0.10.0 → 0.11.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: db8635d968932366f6665d3d14a9481c1d98473f07091721dda012d8bb372397
4
- data.tar.gz: '0398e6c98ac507fa9b29de814fd003a27032c60b59e58901091346727027ce60'
3
+ metadata.gz: ba759b665f6bc72dfb41ad6f501de3ddd00e7047673ac805dddbae20bc6c69fb
4
+ data.tar.gz: e30ecec2128b9f94f4f5f1d55b1b86b035555d49ef6b27f1abeae22e5b0e63b4
5
5
  SHA512:
6
- metadata.gz: d5cb493959983cd2fe0db8a23d6a88709819f515652db1a6fb262be708e6b47dcea8e39f9c2be8b95d7b2d8135eb10f2e63186ed68973454cf988712544c2165
7
- data.tar.gz: ad3e5412c2924f4b4ff49df0fc337b56875227f1ffe5b70455a6537694677dd2e10421562fefe0b4635ea01a0a94926514487f4b3b38c5446e2ca72a3a24d6a5
6
+ metadata.gz: e7784041e0d6e9b42bbfd8dc02dac3bbff8872ba268571c3b1f022a59b390e59fb637dedefb38894f8ee98234db5fa3fd3c1e03e99a8f4f1cd3befc9130ce368
7
+ data.tar.gz: 2fd57d0ad2722e86e03e130799af76ec58828b9d701fd9726a68b5bbf6e1ce6da780ea93553d34a4f7423ade363c13463cbc28e02e4b65348ec389901c05420c
@@ -0,0 +1,31 @@
1
+ name: Test & Lint
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ continue-on-error: ${{ matrix.experimental }}
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ ruby: [ '2.6', '2.7' ]
17
+ experimental: [ false ]
18
+ include:
19
+ - ruby: 'head'
20
+ experimental: true
21
+
22
+ name: Ruby ${{ matrix.ruby }}
23
+ steps:
24
+ - uses: actions/checkout@v2
25
+ - uses: ruby/setup-ruby@v1
26
+ with:
27
+ ruby-version: ${{ matrix.ruby }}
28
+ - run: gem install bundler:2.1.4
29
+ - run: bundle install
30
+ - run: bundle exec rubocop
31
+ - run: bundle exec rspec --format progress
@@ -31,6 +31,7 @@ RSpec/ExampleLength:
31
31
  - 'spec/lib/slack/block_kit/composition/option_group_spec.rb'
32
32
  - 'spec/lib/slack/block_kit/composition/option_spec.rb'
33
33
  - 'spec/lib/slack/block_kit/element/checkboxes_spec.rb'
34
+ - 'spec/lib/slack/block_kit/element/radio_buttons_spec.rb'
34
35
 
35
36
  # Offense count: 4
36
37
  Style/Documentation:
@@ -10,7 +10,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10
10
  - N/A
11
11
 
12
12
  ### Changed
13
-
14
13
  - N/A
15
14
 
16
15
  ### Deprecated
@@ -26,6 +25,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
26
25
  - N/A
27
26
 
28
27
 
28
+ ## [0.11.0] - 2020-10-03
29
+
30
+ ### Added
31
+ - Add `Slack::BlockKit::Element::RadioButtons` (#52 by @caalberts)
32
+
33
+ ### Changed
34
+ - Internal refactoring of `#confirmation_dialog` methods into a shared `Confirmable` module. (#48)
35
+
36
+ ### Fixed
37
+ - Ruby2.7 kwarg deprecation warnings
38
+
39
+
29
40
  ## [0.10.0] - 2020-09-11
30
41
 
31
42
  ### Added
@@ -38,8 +49,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
38
49
  See [releases] for previous changes.
39
50
 
40
51
 
41
-
42
- [Unreleased]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.10.0...HEAD
52
+ [Unreleased]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.11.0...HEAD
53
+ [0.11.0]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.10.0...v0.11.0
43
54
  [0.10.0]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.9.0...v0.10.0
44
55
 
45
56
  [releases]: https://github.com/CGA1123/slack-ruby-block-kit/releases
data/Gemfile CHANGED
@@ -2,5 +2,4 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- # Specify your gem's dependencies in tenios-rb.gemspec
6
5
  gemspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slack-ruby-block-kit (0.10.0)
4
+ slack-ruby-block-kit (0.11.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -15,14 +15,14 @@ GEM
15
15
  method_source (1.0.0)
16
16
  multipart-post (2.1.1)
17
17
  parallel (1.19.2)
18
- parser (2.7.1.4)
18
+ parser (2.7.1.5)
19
19
  ast (~> 2.4.1)
20
20
  pry (0.13.1)
21
21
  coderay (~> 1.1)
22
22
  method_source (~> 1.0)
23
23
  rainbow (3.0.0)
24
24
  rake (13.0.1)
25
- regexp_parser (1.7.1)
25
+ regexp_parser (1.8.0)
26
26
  rexml (3.2.4)
27
27
  rspec (3.9.0)
28
28
  rspec-core (~> 3.9.0)
@@ -39,20 +39,22 @@ GEM
39
39
  rspec-support (3.9.3)
40
40
  rspec_junit_formatter (0.4.1)
41
41
  rspec-core (>= 2, < 4, != 2.12.0)
42
- rubocop (0.90.0)
42
+ rubocop (0.92.0)
43
43
  parallel (~> 1.10)
44
- parser (>= 2.7.1.1)
44
+ parser (>= 2.7.1.5)
45
45
  rainbow (>= 2.2.2, < 4.0)
46
46
  regexp_parser (>= 1.7)
47
47
  rexml
48
- rubocop-ast (>= 0.3.0, < 1.0)
48
+ rubocop-ast (>= 0.5.0)
49
49
  ruby-progressbar (~> 1.7)
50
50
  unicode-display_width (>= 1.4.0, < 2.0)
51
- rubocop-ast (0.3.0)
52
- parser (>= 2.7.1.4)
51
+ rubocop-ast (0.7.0)
52
+ parser (>= 2.7.1.5)
53
+ strscan (>= 1.0.0)
53
54
  rubocop-rspec (1.43.2)
54
55
  rubocop (~> 0.87)
55
56
  ruby-progressbar (1.10.1)
57
+ strscan (1.0.3)
56
58
  unicode-display_width (1.7.0)
57
59
 
58
60
  PLATFORMS
@@ -6,7 +6,7 @@ module Slack
6
6
  module Element; end
7
7
  module Layout; end
8
8
 
9
- VERSION = '0.10.0'
9
+ VERSION = '0.11.0'
10
10
 
11
11
  Dir[File.join(__dir__, 'block_kit', 'composition', '*.rb')].sort.each { |file| require file }
12
12
  Dir[File.join(__dir__, 'block_kit', 'element', '*.rb')].sort.each { |file| require file }
@@ -9,6 +9,22 @@ module Slack
9
9
  #
10
10
  # https://api.slack.com/reference/messaging/composition-objects#confirm
11
11
  class ConfirmationDialog
12
+ # {Confirmable} contains the common behaviour for configuring a
13
+ # {ConfirmationDialog}
14
+ module Confirmable
15
+ def self.included(klass)
16
+ klass.attr_accessor :confirm
17
+ end
18
+
19
+ def confirmation_dialog
20
+ self.confirm = Composition::ConfirmationDialog.new
21
+
22
+ yield(confirm) if block_given?
23
+
24
+ self
25
+ end
26
+ end
27
+
12
28
  def initialize
13
29
  @title, @confirm, @text, @style = nil
14
30
  end
@@ -9,9 +9,9 @@ module Slack
9
9
  #
10
10
  # https://api.slack.com/reference/messaging/block-elements#button
11
11
  class Button
12
- TYPE = 'button'
12
+ include Composition::ConfirmationDialog::Confirmable
13
13
 
14
- attr_accessor :confirm
14
+ TYPE = 'button'
15
15
 
16
16
  def initialize(text:, action_id:, style: nil, emoji: nil, url: nil, value: nil)
17
17
  @text = Composition::PlainText.new(text: text, emoji: emoji)
@@ -23,14 +23,6 @@ module Slack
23
23
  yield(self) if block_given?
24
24
  end
25
25
 
26
- def confirmation_dialog
27
- @confirm = Composition::ConfirmationDialog.new
28
-
29
- yield(@confirm) if block_given?
30
-
31
- @confirm
32
- end
33
-
34
26
  def as_json(*)
35
27
  {
36
28
  type: TYPE,
@@ -39,7 +31,7 @@ module Slack
39
31
  url: @url,
40
32
  value: @value,
41
33
  style: @style,
42
- confirm: @confirm&.as_json
34
+ confirm: confirm&.as_json
43
35
  }.compact
44
36
  end
45
37
  end
@@ -13,9 +13,9 @@ module Slack
13
13
  #
14
14
  # https://api.slack.com/reference/messaging/block-elements#channel-select
15
15
  class ChannelsSelect
16
- TYPE = 'channels_select'
16
+ include Composition::ConfirmationDialog::Confirmable
17
17
 
18
- attr_accessor :confirm
18
+ TYPE = 'channels_select'
19
19
 
20
20
  def initialize(placeholder:, action_id:, initial: nil, emoji: nil)
21
21
  @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
@@ -25,21 +25,13 @@ module Slack
25
25
  yield(self) if block_given?
26
26
  end
27
27
 
28
- def confirmation_dialog
29
- @confirm = Composition::ConfirmationDialog.new
30
-
31
- yield(@confirm) if block_given?
32
-
33
- self
34
- end
35
-
36
28
  def as_json(*)
37
29
  {
38
30
  type: TYPE,
39
31
  placeholder: @placeholder.as_json,
40
32
  action_id: @action_id,
41
33
  initial_channel: @initial_channel,
42
- confirm: @confirm&.as_json
34
+ confirm: confirm&.as_json
43
35
  }.compact
44
36
  end
45
37
  end
@@ -8,15 +8,14 @@ module Slack
8
8
  #
9
9
  # https://api.slack.com/reference/messaging/block-elements#checkboxes
10
10
  class Checkboxes
11
- TYPE = 'checkboxes'
11
+ include Composition::ConfirmationDialog::Confirmable
12
12
 
13
- attr_accessor :confirm
13
+ TYPE = 'checkboxes'
14
14
 
15
15
  def initialize(action_id:)
16
16
  @action_id = action_id
17
17
  @options = []
18
18
  @initial_options = []
19
- @confirm = nil
20
19
 
21
20
  yield(self) if block_given?
22
21
  end
@@ -41,21 +40,13 @@ module Slack
41
40
  self
42
41
  end
43
42
 
44
- def confirmation_dialog
45
- @confirm = Composition::ConfirmationDialog.new
46
-
47
- yield(@confirm) if block_given?
48
-
49
- @confirm
50
- end
51
-
52
43
  def as_json(*)
53
44
  {
54
45
  type: TYPE,
55
46
  action_id: @action_id,
56
47
  options: @options.map(&:as_json),
57
48
  initial_options: @initial_options.any? ? @initial_options.map(&:as_json) : nil,
58
- confirm: @confirm&.as_json
49
+ confirm: confirm&.as_json
59
50
  }.compact
60
51
  end
61
52
  end
@@ -14,9 +14,9 @@ module Slack
14
14
  #
15
15
  # https://api.slack.com/reference/messaging/block-elements#conversation-select
16
16
  class ConversationsSelect
17
- TYPE = 'conversations_select'
17
+ include Composition::ConfirmationDialog::Confirmable
18
18
 
19
- attr_accessor :confirm
19
+ TYPE = 'conversations_select'
20
20
 
21
21
  def initialize(placeholder:, action_id:, initial: nil, emoji: nil)
22
22
  @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
@@ -27,14 +27,6 @@ module Slack
27
27
  yield(self) if block_given?
28
28
  end
29
29
 
30
- def confirmation_dialog
31
- @confirm = Composition::ConfirmationDialog.new
32
-
33
- yield(@confirm) if block_given?
34
-
35
- self
36
- end
37
-
38
30
  def filter(only: nil,
39
31
  exclude_external_shared_channels: nil,
40
32
  exclude_bot_users: nil)
@@ -53,7 +45,7 @@ module Slack
53
45
  placeholder: @placeholder.as_json,
54
46
  action_id: @action_id,
55
47
  initial_conversation: @initial_conversation,
56
- confirm: @confirm&.as_json,
48
+ confirm: confirm&.as_json,
57
49
  filter: @filter&.as_json
58
50
  }.compact
59
51
  end
@@ -10,6 +10,8 @@ module Slack
10
10
  #
11
11
  # https://api.slack.com/reference/messaging/block-elements#datepicker
12
12
  class DatePicker
13
+ include Composition::ConfirmationDialog::Confirmable
14
+
13
15
  TYPE = 'datepicker'
14
16
 
15
17
  def initialize(action_id:, placeholder: nil, initial: nil, emoji: nil)
@@ -25,21 +27,13 @@ module Slack
25
27
  yield(self) if block_given?
26
28
  end
27
29
 
28
- def confirmation_dialog
29
- @confirm = Composition::ConfirmationDialog.new
30
-
31
- yield(@confirm) if block_given?
32
-
33
- self
34
- end
35
-
36
30
  def as_json(*)
37
31
  {
38
32
  type: TYPE,
39
33
  action_id: @action_id,
40
34
  placeholder: @placeholder&.as_json,
41
35
  initial_date: @initial_date,
42
- confirm: @confirm&.as_json
36
+ confirm: confirm&.as_json
43
37
  }.compact
44
38
  end
45
39
  end
@@ -19,28 +19,19 @@ module Slack
19
19
  #
20
20
  # https://api.slack.com/reference/messaging/block-elements#external-select
21
21
  class ExternalSelect
22
- TYPE = 'external_select'
22
+ include Composition::ConfirmationDialog::Confirmable
23
23
 
24
- attr_accessor :confirm
24
+ TYPE = 'external_select'
25
25
 
26
26
  def initialize(placeholder:, action_id:, initial: nil, min_query_length: nil, emoji: nil)
27
27
  @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
28
28
  @action_id = action_id
29
29
  @initial_option = initial
30
30
  @min_query_length = min_query_length
31
- @confirm = nil
32
31
 
33
32
  yield(self) if block_given?
34
33
  end
35
34
 
36
- def confirmation_dialog
37
- @confirm = Composition::ConfirmationDialog.new
38
-
39
- yield(@confirm) if block_given?
40
-
41
- self
42
- end
43
-
44
35
  def as_json(*)
45
36
  {
46
37
  type: TYPE,
@@ -48,7 +39,7 @@ module Slack
48
39
  action_id: @action_id,
49
40
  initial_option: @initial_option&.as_json,
50
41
  min_query_length: @min_query_length,
51
- confirm: @confirm&.as_json
42
+ confirm: confirm&.as_json
52
43
  }.compact
53
44
  end
54
45
  end
@@ -13,35 +13,26 @@ module Slack
13
13
  #
14
14
  # https://api.slack.com/reference/block-kit/block-elements#channel_multi_select
15
15
  class MultiChannelsSelect
16
- TYPE = 'multi_channels_select'
16
+ include Composition::ConfirmationDialog::Confirmable
17
17
 
18
- attr_accessor :confirm
18
+ TYPE = 'multi_channels_select'
19
19
 
20
20
  def initialize(placeholder:, action_id:, initial: nil, emoji: nil, max_selected_items: nil)
21
21
  @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
22
22
  @action_id = action_id
23
23
  @initial_channels = initial
24
- @confirm = nil
25
24
  @max_selected_items = max_selected_items
26
25
 
27
26
  yield(self) if block_given?
28
27
  end
29
28
 
30
- def confirmation_dialog
31
- @confirm = Composition::ConfirmationDialog.new
32
-
33
- yield(@confirm) if block_given?
34
-
35
- self
36
- end
37
-
38
29
  def as_json(*)
39
30
  {
40
31
  type: TYPE,
41
32
  placeholder: @placeholder.as_json,
42
33
  action_id: @action_id,
43
34
  initial_channels: @initial_channels,
44
- confirm: @confirm&.as_json,
35
+ confirm: confirm&.as_json,
45
36
  max_selected_items: @max_selected_items
46
37
  }.compact
47
38
  end
@@ -14,29 +14,20 @@ module Slack
14
14
  #
15
15
  # https://api.slack.com/reference/block-kit/block-elements#conversation_multi_select
16
16
  class MultiConversationsSelect
17
- TYPE = 'multi_conversations_select'
17
+ include Composition::ConfirmationDialog::Confirmable
18
18
 
19
- attr_accessor :confirm
19
+ TYPE = 'multi_conversations_select'
20
20
 
21
21
  def initialize(placeholder:, action_id:, initial: nil, emoji: nil, max_selected_items: nil)
22
22
  @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
23
23
  @action_id = action_id
24
24
  @initial_conversations = initial
25
- @confirm = nil
26
25
  @max_selected_items = max_selected_items
27
26
  @filter = nil
28
27
 
29
28
  yield(self) if block_given?
30
29
  end
31
30
 
32
- def confirmation_dialog
33
- @confirm = Composition::ConfirmationDialog.new
34
-
35
- yield(@confirm) if block_given?
36
-
37
- self
38
- end
39
-
40
31
  def filter(only: nil,
41
32
  exclude_external_shared_channels: nil,
42
33
  exclude_bot_users: nil)
@@ -55,7 +46,7 @@ module Slack
55
46
  placeholder: @placeholder.as_json,
56
47
  action_id: @action_id,
57
48
  initial_conversations: @initial_conversations,
58
- confirm: @confirm&.as_json,
49
+ confirm: confirm&.as_json,
59
50
  max_selected_items: @max_selected_items,
60
51
  filter: @filter&.as_json
61
52
  }.compact
@@ -19,9 +19,9 @@ module Slack
19
19
  #
20
20
  # https://api.slack.com/reference/block-kit/block-elements#external_multi_select
21
21
  class MultiExternalSelect
22
- TYPE = 'multi_external_select'
22
+ include Composition::ConfirmationDialog::Confirmable
23
23
 
24
- attr_accessor :confirm
24
+ TYPE = 'multi_external_select'
25
25
 
26
26
  def initialize(placeholder:, action_id:,
27
27
  initial: nil, min_query_length: nil, emoji: nil, max_selected_items: nil)
@@ -30,20 +30,11 @@ module Slack
30
30
  @action_id = action_id
31
31
  @initial_options = initial
32
32
  @min_query_length = min_query_length
33
- @confirm = nil
34
33
  @max_selected_items = max_selected_items
35
34
 
36
35
  yield(self) if block_given?
37
36
  end
38
37
 
39
- def confirmation_dialog
40
- @confirm = Composition::ConfirmationDialog.new
41
-
42
- yield(@confirm) if block_given?
43
-
44
- self
45
- end
46
-
47
38
  def as_json(*)
48
39
  {
49
40
  type: TYPE,
@@ -51,7 +42,7 @@ module Slack
51
42
  action_id: @action_id,
52
43
  initial_options: @initial_options&.map(&:as_json),
53
44
  min_query_length: @min_query_length,
54
- confirm: @confirm&.as_json,
45
+ confirm: confirm&.as_json,
55
46
  max_selected_items: @max_selected_items
56
47
  }.compact
57
48
  end
@@ -13,14 +13,15 @@ module Slack
13
13
  #
14
14
  # https://api.slack.com/reference/block-kit/block-elements#static_multi_select
15
15
  class MultiStaticSelect
16
+ include Composition::ConfirmationDialog::Confirmable
17
+
16
18
  TYPE = 'multi_static_select'
17
19
 
18
- attr_accessor :confirm, :options, :option_groups, :initial_options
20
+ attr_accessor :options, :option_groups, :initial_options
19
21
 
20
22
  def initialize(placeholder:, action_id:, emoji: nil, max_selected_items: nil)
21
23
  @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
22
24
  @action_id = action_id
23
- @confirm = nil
24
25
  @max_selected_items = max_selected_items
25
26
 
26
27
  @options = nil
@@ -30,14 +31,6 @@ module Slack
30
31
  yield(self) if block_given?
31
32
  end
32
33
 
33
- def confirmation_dialog
34
- @confirm = Composition::ConfirmationDialog.new
35
-
36
- yield(@confirm) if block_given?
37
-
38
- self
39
- end
40
-
41
34
  def option(value:, text:, emoji: nil)
42
35
  @options ||= []
43
36
  @options << Composition::Option.new(
@@ -79,7 +72,7 @@ module Slack
79
72
  options: @options&.map(&:as_json),
80
73
  option_groups: @option_groups&.map(&:as_json),
81
74
  initial_options: @initial_options&.map(&:as_json),
82
- confirm: @confirm&.as_json,
75
+ confirm: confirm&.as_json,
83
76
  max_selected_items: @max_selected_items
84
77
  }.compact
85
78
  end
@@ -13,35 +13,26 @@ module Slack
13
13
  #
14
14
  # https://api.slack.com/reference/block-kit/block-elements#users_multi_select
15
15
  class MultiUsersSelect
16
- TYPE = 'multi_users_select'
16
+ include Composition::ConfirmationDialog::Confirmable
17
17
 
18
- attr_accessor :confirm
18
+ TYPE = 'multi_users_select'
19
19
 
20
20
  def initialize(placeholder:, action_id:, initial: nil, emoji: nil, max_selected_items: nil)
21
21
  @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
22
22
  @action_id = action_id
23
23
  @initial_users = initial
24
- @confirm = nil
25
24
  @max_selected_items = max_selected_items
26
25
 
27
26
  yield(self) if block_given?
28
27
  end
29
28
 
30
- def confirmation_dialog
31
- @confirm = Composition::ConfirmationDialog.new
32
-
33
- yield(@confirm) if block_given?
34
-
35
- self
36
- end
37
-
38
29
  def as_json(*)
39
30
  {
40
31
  type: TYPE,
41
32
  placeholder: @placeholder.as_json,
42
33
  action_id: @action_id,
43
34
  initial_users: @initial_users,
44
- confirm: @confirm&.as_json,
35
+ confirm: confirm&.as_json,
45
36
  max_selected_items: @max_selected_items
46
37
  }.compact
47
38
  end
@@ -15,14 +15,15 @@ module Slack
15
15
  #
16
16
  # https://api.slack.com/reference/messaging/block-elements#overflow
17
17
  class OverflowMenu
18
+ include Composition::ConfirmationDialog::Confirmable
19
+
18
20
  TYPE = 'overflow'
19
21
 
20
- attr_accessor :options, :confirm
22
+ attr_accessor :options
21
23
 
22
24
  def initialize(action_id:)
23
25
  @action_id = action_id
24
26
  @options = []
25
- @confirm = nil
26
27
 
27
28
  yield(self) if block_given?
28
29
  end
@@ -38,20 +39,12 @@ module Slack
38
39
  self
39
40
  end
40
41
 
41
- def confirmation_dialog
42
- @confirm = Composition::ConfirmationDialog.new
43
-
44
- yield(@confirm) if block_given?
45
-
46
- self
47
- end
48
-
49
42
  def as_json(*)
50
43
  {
51
44
  type: TYPE,
52
45
  action_id: @action_id,
53
46
  options: @options.map(&:as_json),
54
- confirm: @confirm&.as_json
47
+ confirm: confirm&.as_json
55
48
  }.compact
56
49
  end
57
50
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Element
6
+ # A radio button group that allows a user to choose one item from a list of possible options.
7
+ #
8
+ # https://api.slack.com/reference/messaging/block-elements#radio
9
+ class RadioButtons
10
+ include Composition::ConfirmationDialog::Confirmable
11
+
12
+ TYPE = 'radio_buttons'
13
+
14
+ attr_accessor :options, :initial_option
15
+
16
+ def initialize(action_id:)
17
+ @action_id = action_id
18
+
19
+ yield(self) if block_given?
20
+ end
21
+
22
+ def option(value:, text:, initial: false)
23
+ option = Composition::Option.new(
24
+ value: value,
25
+ text: text
26
+ )
27
+
28
+ @options ||= []
29
+ @options << option
30
+
31
+ @initial_option = option if initial
32
+
33
+ self
34
+ end
35
+
36
+ def as_json(*)
37
+ {
38
+ type: TYPE,
39
+ action_id: @action_id,
40
+ options: @options&.map(&:as_json),
41
+ initial_option: @initial_option&.as_json,
42
+ confirm: confirm&.as_json
43
+ }.compact
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -13,9 +13,11 @@ module Slack
13
13
  #
14
14
  # https://api.slack.com/reference/messaging/block-elements#static-select
15
15
  class StaticSelect
16
+ include Composition::ConfirmationDialog::Confirmable
17
+
16
18
  TYPE = 'static_select'
17
19
 
18
- attr_accessor :confirm, :options, :option_groups, :initial_option
20
+ attr_accessor :options, :option_groups, :initial_option
19
21
 
20
22
  def initialize(placeholder:, action_id:, emoji: nil)
21
23
  @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
@@ -24,14 +26,6 @@ module Slack
24
26
  yield(self) if block_given?
25
27
  end
26
28
 
27
- def confirmation_dialog
28
- @confirm = Composition::ConfirmationDialog.new
29
-
30
- yield(@confirm) if block_given?
31
-
32
- self
33
- end
34
-
35
29
  def option(value:, text:, emoji: nil)
36
30
  @options ||= []
37
31
  @options << Composition::Option.new(
@@ -72,7 +66,7 @@ module Slack
72
66
  options: @options&.map(&:as_json),
73
67
  option_groups: @option_groups&.map(&:as_json),
74
68
  initial_option: @initial_option&.as_json,
75
- confirm: @confirm&.as_json
69
+ confirm: confirm&.as_json
76
70
  }.compact
77
71
  end
78
72
  end
@@ -13,9 +13,9 @@ module Slack
13
13
  #
14
14
  # https://api.slack.com/reference/messaging/block-elements#users-select
15
15
  class UsersSelect
16
- TYPE = 'users_select'
16
+ include Composition::ConfirmationDialog::Confirmable
17
17
 
18
- attr_accessor :confirm
18
+ TYPE = 'users_select'
19
19
 
20
20
  def initialize(placeholder:, action_id:, initial: nil, emoji: nil)
21
21
  @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
@@ -25,21 +25,13 @@ module Slack
25
25
  yield(self) if block_given?
26
26
  end
27
27
 
28
- def confirmation_dialog
29
- @confirm = Composition::ConfirmationDialog.new
30
-
31
- yield(@confirm) if block_given?
32
-
33
- self
34
- end
35
-
36
28
  def as_json(*)
37
29
  {
38
30
  type: TYPE,
39
31
  placeholder: @placeholder.as_json,
40
32
  action_id: @action_id,
41
33
  initial_user: @initial_user,
42
- confirm: @confirm&.as_json
34
+ confirm: confirm&.as_json
43
35
  }.compact
44
36
  end
45
37
  end
@@ -166,6 +166,16 @@ module Slack
166
166
  accessorise(element)
167
167
  end
168
168
 
169
+ def radio_buttons(action_id:)
170
+ element = Element::RadioButtons.new(
171
+ action_id: action_id
172
+ )
173
+
174
+ yield(element) if block_given?
175
+
176
+ accessorise(element)
177
+ end
178
+
169
179
  def image(url:, alt_text:)
170
180
  accessorise(Element::Image.new(image_url: url, alt_text: alt_text))
171
181
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-ruby-block-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Gregg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-11 00:00:00.000000000 Z
11
+ date: 2020-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -143,8 +143,8 @@ executables: []
143
143
  extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
- - ".circleci/config.yml"
147
146
  - ".github/dependabot.yml"
147
+ - ".github/workflows/ci.yml"
148
148
  - ".gitignore"
149
149
  - ".rspec"
150
150
  - ".rubocop.yml"
@@ -179,6 +179,7 @@ files:
179
179
  - lib/slack/block_kit/element/multi_users_select.rb
180
180
  - lib/slack/block_kit/element/overflow_menu.rb
181
181
  - lib/slack/block_kit/element/plain_text_input.rb
182
+ - lib/slack/block_kit/element/radio_buttons.rb
182
183
  - lib/slack/block_kit/element/static_select.rb
183
184
  - lib/slack/block_kit/element/users_select.rb
184
185
  - lib/slack/block_kit/layout/actions.rb
@@ -212,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
213
  - !ruby/object:Gem::Version
213
214
  version: '0'
214
215
  requirements: []
215
- rubygems_version: 3.0.3
216
+ rubygems_version: 3.1.2
216
217
  signing_key:
217
218
  specification_version: 4
218
219
  summary: A ruby wrapper for Slack's Block Kit
@@ -1,49 +0,0 @@
1
- version: 2
2
- jobs:
3
- build:
4
- docker:
5
- - image: circleci/ruby:2.7
6
-
7
- working_directory: ~/repo
8
-
9
- steps:
10
- - checkout
11
- - restore_cache:
12
- keys:
13
- - v1-dependencies-{{ checksum "Gemfile.lock" }}
14
- - v1-dependencies-
15
-
16
- - run:
17
- name: bundle
18
- command: |
19
- bundle install --jobs=4 --retry=3 --path vendor/bundle
20
-
21
- - save_cache:
22
- paths:
23
- - ./vendor/bundle
24
- key: v1-dependencies-{{ checksum "Gemfile.lock" }}
25
-
26
- - run:
27
- name: rspec
28
- command: |
29
- mkdir /tmp/test-results
30
- TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
31
- circleci tests split --split-by=timings)"
32
-
33
- bundle exec rspec \
34
- --format progress \
35
- --format RspecJunitFormatter \
36
- --out /tmp/test-results/rspec.xml \
37
- --format progress \
38
- $TEST_FILES
39
-
40
- # collect reports
41
- - store_test_results:
42
- path: /tmp/test-results
43
- - store_artifacts:
44
- path: /tmp/test-results
45
- destination: test-results
46
-
47
- - run:
48
- name: rubocop
49
- command: bundle exec rubocop -p