Class: Banacle::Slack::Attachment
- Inherits:
-
Struct
- Object
- Struct
- Banacle::Slack::Attachment
- Defined in:
- lib/banacle/slack.rb
Defined Under Namespace
Classes: ValidationError
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#attachment_type ⇒ Object
Returns the value of attribute attachment_type.
-
#callback_id ⇒ Object
Returns the value of attribute callback_id.
-
#color ⇒ Object
Returns the value of attribute color.
-
#fallback ⇒ Object
Returns the value of attribute fallback.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(*args) ⇒ Attachment
constructor
A new instance of Attachment.
- #set_default! ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(*args) ⇒ Attachment
Returns a new instance of Attachment.
51 52 53 54 55 56 |
# File 'lib/banacle/slack.rb', line 51 def initialize(*args) super self.set_default! self.validate! self end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions
47 48 49 |
# File 'lib/banacle/slack.rb', line 47 def actions @actions end |
#attachment_type ⇒ Object
Returns the value of attribute attachment_type
47 48 49 |
# File 'lib/banacle/slack.rb', line 47 def @attachment_type end |
#callback_id ⇒ Object
Returns the value of attribute callback_id
47 48 49 |
# File 'lib/banacle/slack.rb', line 47 def callback_id @callback_id end |
#color ⇒ Object
Returns the value of attribute color
47 48 49 |
# File 'lib/banacle/slack.rb', line 47 def color @color end |
#fallback ⇒ Object
Returns the value of attribute fallback
47 48 49 |
# File 'lib/banacle/slack.rb', line 47 def fallback @fallback end |
#text ⇒ Object
Returns the value of attribute text
47 48 49 |
# File 'lib/banacle/slack.rb', line 47 def text @text end |
Instance Method Details
#as_json ⇒ Object
81 82 83 |
# File 'lib/banacle/slack.rb', line 81 def as_json self.to_h.tap { |h| h[:actions] = h[:actions].map(&:as_json) } end |
#set_default! ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/banacle/slack.rb', line 58 def set_default! self.text ||= '' self.fallback ||= '' self.callback_id ||= '' self.color ||= '' self. ||= '' self.actions ||= [] end |
#validate! ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/banacle/slack.rb', line 67 def validate! %i(text fallback callback_id color attachment_type).each do |label| unless self.send(label).is_a?(String) raise ValidationError.new("#{attr} must be String") end end self.actions.each do |a| unless a.is_a?(Slack::Action) raise ValidationError.new("One of actions #{a.inspect} must be Slack::Action") end end end |