Class: Banacle::Slack::Action
- Inherits:
-
Struct
- Object
- Struct
- Banacle::Slack::Action
- Defined in:
- lib/banacle/slack.rb
Defined Under Namespace
Classes: ValidationError
Instance Attribute Summary collapse
-
#confirm ⇒ Object
Returns the value of attribute confirm.
-
#name ⇒ Object
Returns the value of attribute name.
-
#style ⇒ Object
Returns the value of attribute style.
-
#text ⇒ Object
Returns the value of attribute text.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
- .approve_button ⇒ Object
- .build(value, style, type, confirm) ⇒ Object
- .build_button(value, style: 'default', confirm: nil) ⇒ Object
- .cancel_button ⇒ Object
- .reject_button ⇒ Object
Instance Method Summary collapse
- #approved? ⇒ Boolean
- #as_json ⇒ Object
- #cancelled? ⇒ Boolean
-
#initialize(*args) ⇒ Action
constructor
A new instance of Action.
- #rejected? ⇒ Boolean
- #set_default! ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(*args) ⇒ Action
Returns a new instance of Action.
109 110 111 112 113 114 |
# File 'lib/banacle/slack.rb', line 109 def initialize(*args) super self.set_default! self.validate! self end |
Instance Attribute Details
#confirm ⇒ Object
Returns the value of attribute confirm
86 87 88 |
# File 'lib/banacle/slack.rb', line 86 def confirm @confirm end |
#name ⇒ Object
Returns the value of attribute name
86 87 88 |
# File 'lib/banacle/slack.rb', line 86 def name @name end |
#style ⇒ Object
Returns the value of attribute style
86 87 88 |
# File 'lib/banacle/slack.rb', line 86 def style @style end |
#text ⇒ Object
Returns the value of attribute text
86 87 88 |
# File 'lib/banacle/slack.rb', line 86 def text @text end |
#type ⇒ Object
Returns the value of attribute type
86 87 88 |
# File 'lib/banacle/slack.rb', line 86 def type @type end |
#value ⇒ Object
Returns the value of attribute value
86 87 88 |
# File 'lib/banacle/slack.rb', line 86 def value @value end |
Class Method Details
.approve_button ⇒ Object
89 90 91 |
# File 'lib/banacle/slack.rb', line 89 def self. self.('approve', style: 'primary', confirm: Confirm.approve) end |
.build(value, style, type, confirm) ⇒ Object
105 106 107 |
# File 'lib/banacle/slack.rb', line 105 def self.build(value, style, type, confirm) self.new(name: value, text: value.capitalize, style: style, type: type, value: value, confirm: confirm) end |
.build_button(value, style: 'default', confirm: nil) ⇒ Object
101 102 103 |
# File 'lib/banacle/slack.rb', line 101 def self.(value, style: 'default', confirm: nil) self.build(value, style, 'button', confirm) end |
.cancel_button ⇒ Object
97 98 99 |
# File 'lib/banacle/slack.rb', line 97 def self. self.('cancel') end |
.reject_button ⇒ Object
93 94 95 |
# File 'lib/banacle/slack.rb', line 93 def self. self.('reject', style: 'danger') end |
Instance Method Details
#approved? ⇒ Boolean
136 137 138 |
# File 'lib/banacle/slack.rb', line 136 def approved? self.value == 'approve' end |
#as_json ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'lib/banacle/slack.rb', line 148 def as_json self.to_h.tap do |h| if h[:confirm] h[:confirm] = h[:confirm].as_json else h.delete(:confirm) end end end |
#cancelled? ⇒ Boolean
144 145 146 |
# File 'lib/banacle/slack.rb', line 144 def cancelled? self.value == 'cancel' end |
#rejected? ⇒ Boolean
140 141 142 |
# File 'lib/banacle/slack.rb', line 140 def rejected? self.value == 'reject' end |
#set_default! ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/banacle/slack.rb', line 116 def set_default! self.name ||= '' self.text ||= '' self.style ||= '' self.type ||= '' self.value ||= '' end |
#validate! ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/banacle/slack.rb', line 124 def validate! %i(name text style type value).each do |label| unless self.send(label).is_a?(String) raise ValidationError.new("#{attr} must be String") end end if self.confirm && !self.confirm.is_a?(Confirm) raise ValidationError.new("confirm must be Slack::Confirm") end end |