Sha256: 509ab74a733657cbcd7e737cbb70abc1d62e211fe4e03a4db7a395a793ec9c94

Contents?: true

Size: 1.59 KB

Versions: 21

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

module RubyRabbitmqJanus
  module Tools
    # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
    # Load files json in config/request.
    # This file is used for sending a request to RabbitMQ
    # @!attribute [r] requests
    class Requests
      include Singleton

      attr_reader :requests

      # Define folder to request
      PATH_REQUEST = 'config/requests/'

      # Load all requests in folder
      def initialize
        @requests = {}
        Tools::Log.instance.info "Loading all requests in : #{PATH_REQUEST}"
        Dir[File.join(PATH_REQUEST, '*')].count do |file|
          if File.file?(file)
            read_file(file)
          elsif File.directory?(file)
            each_folder(File.basename(file))
          end
        end
      end

      private

      # Run folder contains templates json
      def each_folder(subfolder)
        Dir[File.join(PATH_REQUEST + subfolder, '*')].count do |file|
          if File.file?(file)
            read_folder(subfolder.gsub('/', '::') + '::', file)
          elsif File.directory?(file)
            each_folder(subfolder + '/' + File.basename(file))
          end
        end
      end

      # Add template json to requests array
      # @param file [File]
      def read_file(file)
        @requests[File.basename(file, '.json').to_s] = File.path(file)
      end

      # Add template json to requests array with a path
      # @param folder [Dir]
      # @param file [File]
      def read_folder(folder, file)
        @requests[folder + File.basename(file, '.json').to_s] = File.path(file)
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-1.1.12 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.1.11 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.1.10 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.1.9 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.1.8 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.1.7 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.1.6 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.1.5 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.1.4 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.1.3 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.1.2 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.1.1 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.1.0 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.0.8 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.0.7 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.0.6 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.0.5 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.0.4 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.0.3 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.0.2 lib/rrj/tools/requests.rb