Sha256: aa363068531bbb268f5d3e16cd87e35429280ac5b1297aadad20b9c7858777d3

Contents?: true

Size: 1.53 KB

Versions: 21

Compression:

Stored size: 1.53 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 Janus
    #
    # @!attribute [r] requests
    #   @return [Hash] It's a hash with name and path to request.
    #
    # @see file:/config/requests.md For more information to type requests used.
    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

      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

      def read_file(file)
        @requests[File.basename(file, '.json').to_s] = File.path(file)
      end

      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-2.0.0.pre.108 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.0.0 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.0.0.pre.106 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.0.0.pre.101 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.0.0.pre.100 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.0.0.pre.97 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.0.0.pre.96 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.0.0.pre.95 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.0.0.pre.42 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-1.2.9 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.2.8 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.2.7 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.2.7.pre.alpha lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.2.6 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.2.5 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.2.4 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.2.3.pre.53 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.2.3 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.2.2 lib/rrj/tools/requests.rb
ruby_rabbitmq_janus-1.2.1 lib/rrj/tools/requests.rb