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-2.7.2.pre.306 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.305 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.302 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.297 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.296 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.286 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.285 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.2.pre.284 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.1 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.1.pre.274 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.0.pre.272 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.0 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.0.pre.269 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.7.0.pre.267 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.6.0 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.6.0.pre.263 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.6.0.pre.261 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.6.0.pre.260 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.6.0.pre.259 lib/rrj/tools/gem/requests.rb
ruby_rabbitmq_janus-2.6.0.pre.258 lib/rrj/tools/gem/requests.rb