Sha256: 05328c7ef5a50a27c7bd161eedd4012f82aec1255c96c756c1b67e54463bb376

Contents?: true

Size: 510 Bytes

Versions: 14

Compression:

Stored size: 510 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  # A concern with the components needed when you want a model to have a component.
  module Randomable
    extend ActiveSupport::Concern

    class_methods do
      # Public: Randomly orders a collection given a seed.
      def order_randomly(seed)
        transaction do
          connection.execute("SELECT setseed(#{connection.quote(seed)})")
          order(Arel.sql("RANDOM()")).load
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
decidim-core-0.23.6 lib/decidim/randomable.rb
decidim-core-0.23.5 lib/decidim/randomable.rb
decidim-core-0.23.4 lib/decidim/randomable.rb
decidim-core-0.23.3 lib/decidim/randomable.rb
decidim-core-0.23.2 lib/decidim/randomable.rb
decidim-core-0.23.1 lib/decidim/randomable.rb
decidim-core-0.23.1.rc1 lib/decidim/randomable.rb
decidim-core-0.23.0 lib/decidim/randomable.rb
decidim-core-0.22.0 lib/decidim/randomable.rb
decidim-core-0.21.0 lib/decidim/randomable.rb
decidim-core-0.20.1 lib/decidim/randomable.rb
decidim-core-0.20.0 lib/decidim/randomable.rb
decidim-core-0.19.1 lib/decidim/randomable.rb
decidim-core-0.19.0 lib/decidim/randomable.rb