Class: Kanal::Interfaces::Pachka::Plugins::PachkaIntegrationPlugin
- Inherits:
-
Core::Plugins::Plugin
- Object
- Core::Plugins::Plugin
- Kanal::Interfaces::Pachka::Plugins::PachkaIntegrationPlugin
- Includes:
- Logger
- Defined in:
- lib/kanal/interfaces/pachka/plugins/pachka_integration_plugin.rb
Overview
Pachka integration plugin for parameters and conditions and hooks registration
Instance Method Summary collapse
- #name ⇒ Object
- #register_conditions(core) ⇒ Object
- #register_hooks(core) ⇒ Object
- #register_input_parameters(core) ⇒ Object
- #register_output_parameters(core) ⇒ Object
-
#setup(core) ⇒ void
<description>.
Instance Method Details
#name ⇒ Object
16 17 18 |
# File 'lib/kanal/interfaces/pachka/plugins/pachka_integration_plugin.rb', line 16 def name :pachka_integration end |
#register_conditions(core) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/kanal/interfaces/pachka/plugins/pachka_integration_plugin.rb', line 62 def register_conditions(core) core.add_condition_pack :pachka do add_condition :query do with_argument met? do |input, _core, argument| input.pachka_query == argument end end add_condition :command do with_argument met? do |input, _core, argument| input.pachka_command.to_sym == argument || input.pachka_command == argument end end add_condition :text do with_argument met? do |input, _core, argument| input.pachka_text == argument end end end end |
#register_hooks(core) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/kanal/interfaces/pachka/plugins/pachka_integration_plugin.rb', line 46 def register_hooks(core) core.hooks.attach :input_before_router do |input| input.pachka_command = input.pachka_query.split.first[1..] # "/hello" transforms to "hello" input.pachka_text = input.pachka_query.split[1..].join " " # removes command and leaves just message rescue e logger.error "Error parsing input.pachka_query to populate input.pachka_command and input.pachka_text! Query: #{input.pachka_query} More info: #{e.}" input.pachka_command = "ERROR" if input.pachka_command.nil? input.pachka_text = "ERROR" if input.pachka_text.nil? end core.hooks.attach :output_before_returned do |input, output| output.pachka_entity_id = input.pachka_entity_id if output.pachka_entity_id.nil? output.pachka_entity_type = input.pachka_entity_type if output.pachka_entity_type.nil? end end |
#register_input_parameters(core) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/kanal/interfaces/pachka/plugins/pachka_integration_plugin.rb', line 31 def register_input_parameters(core) core.register_input_parameter :pachka_query, readonly: true core.register_input_parameter :pachka_entity_type, readonly: true core.register_input_parameter :pachka_entity_id, readonly: true core.register_input_parameter :pachka_command, readonly: true core.register_input_parameter :pachka_text, readonly: true end |
#register_output_parameters(core) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/kanal/interfaces/pachka/plugins/pachka_integration_plugin.rb', line 39 def register_output_parameters(core) core.register_output_parameter :pachka_entity_type core.register_output_parameter :pachka_entity_id core.register_output_parameter :pachka_text core.register_output_parameter :pachka_file_path end |
#setup(core) ⇒ void
This method returns an undefined value.
Returns <description>.
24 25 26 27 28 29 |
# File 'lib/kanal/interfaces/pachka/plugins/pachka_integration_plugin.rb', line 24 def setup(core) register_input_parameters core register_output_parameters core register_conditions core register_hooks core end |