Sha256: fd2ac7aa875f186eb998407b00207b0f73fae3b1f2ed5e8f92e9393e43c4ef61

Contents?: true

Size: 1.62 KB

Versions: 40

Compression:

Stored size: 1.62 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 = {}
        ::Log.info "Loading all requests in : #{PATH_REQUEST}"
        Dir[File.join(PATH_REQUEST, '*')].count { |file| each_files(file) }
      rescue
        raise Errors::Tools::Request::Initializer
      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

      def each_files(file)
        if File.file?(file)
          read_file(file)
        elsif File.directory?(file)
          each_folder(File.basename(file))
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-3.0.0.pre.336 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-3.0.0.pre.335 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-3.0.0.pre.334 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-3.0.0.pre.330 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-3.0.0.pre.328 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-3.0.0.pre.327 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.322 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.320 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.319 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.318 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.317 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.316 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.315 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.314 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.312 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.310 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.309 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.308 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.307 lib/rrj/tools/gem/requests.rb