6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/block_kit/concerns/has_options.rb', line 6
def self.new(limit:)
Module.new do
extend ActiveSupport::Concern
included do
attribute :options, Types::Array.of(Composition::Option)
validates :options,
presence: {unless: ->(block) { block.respond_to?(:option_groups) }},
length: {maximum: limit, message: "is too long (maximum is %{count} options)"},
"block_kit/validators/associated": true
fixes :options, truncate: {maximum: limit, dangerous: true}, associated: true
dsl_method :options, as: :option, required_fields: [:text, :value], yields: false
end
def as_json(*)
super.merge(options: options&.map(&:as_json))
end
end
end
|