Class: Banacle::SlashCommand::Command
- Inherits:
-
Object
- Object
- Banacle::SlashCommand::Command
- Defined in:
- lib/banacle/slash_command/command.rb
Constant Summary collapse
- CREATE_ACTION =
'create'.freeze
- DELETE_ACTION =
'delete'.freeze
- PERMITTED_ACTIONS =
[CREATE_ACTION, DELETE_ACTION].freeze
- CODE_BLOCK_JSON_REGEX =
/```([^`]+)```/.freeze
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#cidr_blocks ⇒ Object
readonly
Returns the value of attribute cidr_blocks.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#vpc_id ⇒ Object
readonly
Returns the value of attribute vpc_id.
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(action:, region:, vpc_id:, cidr_blocks:) ⇒ Command
constructor
A new instance of Command.
- #to_code_block ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(action:, region:, vpc_id:, cidr_blocks:) ⇒ Command
Returns a new instance of Command.
20 21 22 23 24 25 |
# File 'lib/banacle/slash_command/command.rb', line 20 def initialize(action:, region:, vpc_id:, cidr_blocks:) @action = action @region = region @vpc_id = vpc_id @cidr_blocks = cidr_blocks end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
27 28 29 |
# File 'lib/banacle/slash_command/command.rb', line 27 def action @action end |
#cidr_blocks ⇒ Object (readonly)
Returns the value of attribute cidr_blocks.
27 28 29 |
# File 'lib/banacle/slash_command/command.rb', line 27 def cidr_blocks @cidr_blocks end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
27 28 29 |
# File 'lib/banacle/slash_command/command.rb', line 27 def region @region end |
#vpc_id ⇒ Object (readonly)
Returns the value of attribute vpc_id.
27 28 29 |
# File 'lib/banacle/slash_command/command.rb', line 27 def vpc_id @vpc_id end |
Class Method Details
.new_from_original_message(message) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/banacle/slash_command/command.rb', line 13 def self.() original_json = JSON.parse( .match(CODE_BLOCK_JSON_REGEX)[1].strip, symbolize_names: true, ) new(**original_json) end |
Instance Method Details
#execute ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/banacle/slash_command/command.rb', line 29 def execute case action when CREATE_ACTION create_nacl when DELETE_ACTION delete_nacl else # Do nothing end end |
#to_code_block ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/banacle/slash_command/command.rb', line 40 def to_code_block <<-EOS ``` #{JSON.pretty_generate(self.to_h)} ``` EOS end |
#to_h ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/banacle/slash_command/command.rb', line 48 def to_h { action: action, region: region, vpc_id: vpc_id, cidr_blocks: cidr_blocks, } end |