Class: ActionAlexa::Intent::Registry
- Inherits:
-
Object
- Object
- ActionAlexa::Intent::Registry
- Defined in:
- lib/action_alexa/intent/registry.rb
Overview
The registry will auto-discover and auto-load and intent files found within the intents folder (configurable). Default path to search is Rails.root/app/intents/*_intents.rb The classes loaded should inherit from ActionAlexa::Intent::Base
Class Method Summary collapse
- .find_intent(intent) ⇒ Object
- .intents ⇒ Object
- .load_registry! ⇒ Object
- .register_intent(intent) ⇒ Object
Class Method Details
.find_intent(intent) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/action_alexa/intent/registry.rb', line 16 def self.find_intent(intent) load_registry! if intents.empty? intent_name = "#{intent}Intent" intents[intent_name] end |
.intents ⇒ Object
8 9 10 |
# File 'lib/action_alexa/intent/registry.rb', line 8 def self.intents @intents ||= {} end |
.load_registry! ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/action_alexa/intent/registry.rb', line 23 def self.load_registry! intents_path = File.join( ActionAlexa.config.root, 'app', 'intents', '*_intent.rb' ) Dir.glob(intents_path).sort.each do |intent_file| require intent_file class_name = intent_file.split('/').last.gsub(/\.rb/, '') register_intent(class_name.split('_').collect(&:capitalize).join) end end |
.register_intent(intent) ⇒ Object
12 13 14 |
# File 'lib/action_alexa/intent/registry.rb', line 12 def self.register_intent(intent) intents[intent] = intent.constantize end |