Class: BlockKit::Surfaces::Base
- Defined in:
- lib/block_kit/surfaces/base.rb
Constant Summary collapse
- MAX_BLOCKS =
100- SUPPORTED_BLOCKS =
[ Layout::Actions, Layout::Context, Layout::Divider, Layout::Header, Layout::Image, Layout::Input, Layout::RichText, Layout::Section, Layout::Video ]
Class Method Summary collapse
Instance Method Summary collapse
-
#append(block) ⇒ Object
Overridden to return ‘self`, allowing chaining.
- #as_json ⇒ Object
- #image(alt_text:, image_url: nil, slack_file: nil, title: nil, emoji: nil, block_id: nil) ⇒ Object
-
#initialize(attributes = {}) ⇒ Base
constructor
A new instance of Base.
Methods inherited from Base
#==, fix, #fix_validation_errors, #fix_validation_errors!, fixes, #inspect, inspect, #pretty_print, #to_json
Constructor Details
Class Method Details
.inherited(subclass) ⇒ Object
48 49 50 |
# File 'lib/block_kit/surfaces/base.rb', line 48 def self.inherited(subclass) subclass.attribute_fixers = attribute_fixers.deep_dup end |
Instance Method Details
#append(block) ⇒ Object
Overridden to return ‘self`, allowing chaining.
67 68 69 70 71 |
# File 'lib/block_kit/surfaces/base.rb', line 67 def append(block) blocks << block self end |
#as_json ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/block_kit/surfaces/base.rb', line 73 def as_json(*) super.merge( blocks: blocks&.map(&:as_json), private_metadata: , callback_id: callback_id, external_id: external_id ).compact end |
#image(alt_text:, image_url: nil, slack_file: nil, title: nil, emoji: nil, block_id: nil) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/block_kit/surfaces/base.rb', line 58 def image(alt_text:, image_url: nil, slack_file: nil, title: nil, emoji: nil, block_id: nil) if (image_url.nil? && slack_file.nil?) || (image_url && slack_file) raise ArgumentError, "Must provide either image_url or slack_file, but not both." end append(Layout::Image.new(image_url: image_url, slack_file: slack_file, alt_text: alt_text, title: title, block_id: block_id, emoji: emoji)) end |