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 29 |
# File 'lib/block_kit/blocks.rb', line 24 def initialize(attributes = {}) attributes = attributes.with_indifferent_access attributes[:blocks] ||= [] super end |
Instance Method Details
#append(block) ⇒ Object
Overridden to return ‘self`, allowing chaining.
40 41 42 43 44 |
# File 'lib/block_kit/blocks.rb', line 40 def append(block) blocks << block self end |
#as_json ⇒ Object
46 47 48 |
# File 'lib/block_kit/blocks.rb', line 46 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
31 32 33 34 35 36 37 |
# File 'lib/block_kit/blocks.rb', line 31 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 |