lib/slack/block_kit/element/checkboxes.rb in slack-ruby-block-kit-0.11.0 vs lib/slack/block_kit/element/checkboxes.rb in slack-ruby-block-kit-0.12.0
- old
+ new
@@ -13,42 +13,40 @@
TYPE = 'checkboxes'
def initialize(action_id:)
@action_id = action_id
@options = []
- @initial_options = []
yield(self) if block_given?
end
- def option(value:, text:, description: nil)
+ def option(value:, text:, initial: false, description: nil)
@options << Composition::Option.new(
value: value,
text: text,
- description: description
+ description: description,
+ initial: initial
)
self
end
- def initial(value:, text:, description: nil)
- @initial_options << Composition::Option.new(
- value: value,
- text: text,
- description: description
- )
-
- self
- end
-
def as_json(*)
{
type: TYPE,
action_id: @action_id,
options: @options.map(&:as_json),
- initial_options: @initial_options.any? ? @initial_options.map(&:as_json) : nil,
+ initial_options: initial_options&.map(&:as_json),
confirm: confirm&.as_json
}.compact
+ end
+
+ private
+
+ def initial_options
+ initial = @options.select(&:initial?)
+
+ initial.empty? ? nil : initial
end
end
end
end
end