Sha256: 1e8bd0fef2ea40f13ecf697a2384244240bb5ae2cae9fba4219b7e4af3a5918b

Contents?: true

Size: 1.29 KB

Versions: 7

Compression:

Stored size: 1.29 KB

Contents

require_relative './skill'

module Ralyxa
  class RegisterIntents
    DEFAULT_INTENTS_DIRECTORY = './intents'.freeze

    def initialize(intents_directory, alexa_skill_class)
      @intents_directory = intents_directory
      @alexa_skill_class = alexa_skill_class
    end

    def self.run(intents_directory = DEFAULT_INTENTS_DIRECTORY, alexa_skill_class = Ralyxa::Skill)
      new(intents_directory, alexa_skill_class).run
    end

    def run
      warn NO_INTENT_DECLARATIONS_FOUND if intent_declarations.empty?

      intent_declarations.each do |intent_declaration|
        alexa_skill_class.class_eval intent_declaration
      end
    end

    private

    attr_reader :intents_directory, :alexa_skill_class

    def intent_declarations
      @intent_declarations ||=
        Dir.glob("#{intents_directory}/*.rb")
           .map { |relative_path| File.expand_path(relative_path) }
           .map { |intent_declaration_path| File.open(intent_declaration_path).read }
    end

    heredoc = <<~HEREDOC
      \e[33m
      WARNING: You haven't defined any intent declarations.

      Please define intent declarations inside a directory called 'intents',
      on the same directory level as the runfile for your server application.
      \e[0m
    HEREDOC
    NO_INTENT_DECLARATIONS_FOUND = heredoc.freeze
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
ralyxa-lambda-1.9.0 lib/ralyxa/register_intents.rb
ralyxa-lambda-1.8.0 lib/ralyxa/register_intents.rb
ralyxa-1.8.0 lib/ralyxa/register_intents.rb
ralyxa-1.7.0 lib/ralyxa/register_intents.rb
ralyxa-1.6.2 lib/ralyxa/register_intents.rb
ralyxa-1.6.1 lib/ralyxa/register_intents.rb
ralyxa-1.6.0 lib/ralyxa/register_intents.rb