Sha256: aaa0887dc5f108bc002914074c7e3f9e77ee2a93c167e105ae58fcbe15a46c2f

Contents?: true

Size: 1.51 KB

Versions: 8

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

# :reek:UtilityFunction

module RubyRabbitmqJanus
  module Models
    # Add method for JanusInstance model
    module JanusInstanceMethods
      extend ActiveSupport::Concern

      # Class methods for JanusInstance model
      module ClassMethods
        # Disable an instance
        def disable(session_id)
          JanusInstance.find_by(session: session_id).set(enable: false)
        end

        # Clean all instance disabled
        def destroys
          JanusInstance.where(enable: false).delete_all
        end

        # Search a record by instance number
        def find_by_instance(instance_search)
          JanusInstance.find_by(instance: instance_search)
        rescue
          false
        end

        # Search a record by session number
        def find_by_session(session_search)
          JanusInstance.find_by(session: session_search)
        rescue
          nil
        end

        # Get all instance active
        def enabled
          JanusInstance.where(enable: true)
        end

        # Get all instance not active
        def disabled
          JanusInstance.where(enable: false)
        end
      end

      private

      def search_initializer(options)
        if File.basename($PROGRAM_NAME) == 'rake'
          ::RRJ.start_transaction(options) do |transaction|
            yield(transaction)
          end
        else
          ::RRJ.start_transaction(true, options) do |transaction|
            yield(transaction)
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-2.5.1.pre.217 lib/rrj/models/concerns/janus_instance_methods.rb
ruby_rabbitmq_janus-2.5.1 lib/rrj/models/concerns/janus_instance_methods.rb
ruby_rabbitmq_janus-2.5.1.pre.215 lib/rrj/models/concerns/janus_instance_methods.rb
ruby_rabbitmq_janus-2.5.0 lib/rrj/models/concerns/janus_instance_methods.rb
ruby_rabbitmq_janus-2.5.0.pre.213 lib/rrj/models/concerns/janus_instance_methods.rb
ruby_rabbitmq_janus-2.5.0.pre.210 lib/rrj/models/concerns/janus_instance_methods.rb
ruby_rabbitmq_janus-2.5.0.pre.209 lib/rrj/models/concerns/janus_instance_methods.rb
ruby_rabbitmq_janus-2.4.0.pre.208 lib/rrj/models/concerns/janus_instance_methods.rb