6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/block_kit/concerns/plain_text_emoji_assignment.rb', line 6
def self.new(*attributes)
Module.new do
define_method(:initialize) do |attrs = {}, &block|
raise ArgumentError, "expected `attributes' to be a Hash, got #{attrs.class}" unless attrs.is_a?(Hash)
emoji = attrs.delete(:emoji)
super(attrs, &block)
unless emoji.nil?
attributes.each do |attribute|
text = public_send(attribute)
public_send(:"#{attribute}=", Composition::PlainText.new) if text.nil?
public_send(attribute).emoji = emoji
end
end
end
attributes.each do |attribute|
define_method(:"#{attribute}=") do |value|
text = public_send(attribute)
if !text&.emoji.nil? && value.is_a?(String)
value = Composition::PlainText.new(text: value, emoji: text.emoji)
end
super(value)
end
end
end
end
|