Class: Messenger::Components::Attachment
- Inherits:
-
Object
- Object
- Messenger::Components::Attachment
show all
- Defined in:
- lib/messenger/components/attachment.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Attachment.
4
5
6
|
# File 'lib/messenger/components/attachment.rb', line 4
def initialize
raise 'This class is abstract!'
end
|
Instance Method Details
#all_attributes ⇒ Object
17
18
19
20
|
# File 'lib/messenger/components/attachment.rb', line 17
def all_attributes
return instance_values unless defined?(flattened_attributes)
instance_values.merge! flattened_attributes
end
|
#allowed_attribute?(attribute) ⇒ Boolean
26
27
28
|
# File 'lib/messenger/components/attachment.rb', line 26
def allowed_attribute?(attribute)
self.class::ATTRIBUTES.include?(attribute)
end
|
#build ⇒ Object
8
9
10
11
12
13
14
15
|
# File 'lib/messenger/components/attachment.rb', line 8
def build
{
attachment: {
type: @type,
payload: payload
}
}
end
|
#build_elements(elements) ⇒ Object
30
31
32
|
# File 'lib/messenger/components/attachment.rb', line 30
def build_elements(elements)
elements.map { |element| element.build } if elements.present?
end
|
#payload ⇒ Object
22
23
24
|
# File 'lib/messenger/components/attachment.rb', line 22
def payload
all_attributes.select { |attribute, value| allowed_attribute?(attribute) && value.present? }
end
|