Module: Messenger::Components::Attachment
- Included in:
- Elements::Image, Elements::Video, Templates::Buttons, Templates::Generic, Templates::Receipt
- Defined in:
- lib/messenger/components/attachment.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #all_attributes ⇒ Object
- #allowed_attribute?(attribute) ⇒ Boolean
- #build ⇒ Object
- #build_elements(elements) ⇒ Object
- #payload ⇒ Object
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/messenger/components/attachment.rb', line 4 def type @type end |
Instance Method Details
#all_attributes ⇒ Object
15 16 17 18 |
# File 'lib/messenger/components/attachment.rb', line 15 def all_attributes return instance_values unless defined?(flattened_attributes) instance_values.merge! flattened_attributes end |
#allowed_attribute?(attribute) ⇒ Boolean
24 25 26 |
# File 'lib/messenger/components/attachment.rb', line 24 def allowed_attribute?(attribute) self.class::ATTRIBUTES.include?(attribute) end |
#build ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/messenger/components/attachment.rb', line 6 def build { attachment: { type: @type, payload: payload } } end |
#build_elements(elements) ⇒ Object
28 29 30 |
# File 'lib/messenger/components/attachment.rb', line 28 def build_elements(elements) elements.map { |element| element.build } if elements.present? end |
#payload ⇒ Object
20 21 22 |
# File 'lib/messenger/components/attachment.rb', line 20 def payload all_attributes.select { |attribute, value| allowed_attribute?(attribute) && value.present? } end |