Class: BlockKit::Blocks
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 = {}) ⇒ Blocks
constructor
A new instance of Blocks.
Methods inherited from Base
#==, fix, #fix_validation_errors, #fix_validation_errors!, fixes, inherited, inspect, #inspect, #pretty_print, #to_json
Constructor Details
#initialize(attributes = {}) ⇒ Blocks
Returns a new instance of Blocks.
24 25 26 27 28 |
# File 'lib/block_kit/blocks.rb', line 24 def initialize(attributes = {}) attributes = {blocks: attributes} if attributes.is_a?(Array) super end |
Instance Method Details
#append(block) ⇒ Object
Overridden to return ‘self`, allowing chaining.
39 40 41 42 43 |
# File 'lib/block_kit/blocks.rb', line 39 def append(block) blocks << block self end |
#as_json ⇒ Object
45 46 47 |
# File 'lib/block_kit/blocks.rb', line 45 def as_json(*) blocks&.map(&:as_json) end |
#image(alt_text:, image_url: nil, slack_file: nil, title: nil, emoji: nil, block_id: nil) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/block_kit/blocks.rb', line 30 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 |