Sha256: ee7d797a44772612190f7b4e11faed2e8a56367f204179c35a37a5f922cfa2c2

Contents?: true

Size: 421 Bytes

Versions: 4

Compression:

Stored size: 421 Bytes

Contents

# frozen_string_literal: true

module ActsAsFavoritor
  module FavoritorLib
    def build_result_for_scopes(scopes)
      return if scopes.empty?

      scopes = sanitized_scopes(scopes)
      result = scopes.map { |scope| [scope, yield(scope)] }.to_h

      return result[scopes.first] if scopes.size == 1

      result
    end

    private

    def sanitized_scopes(scopes)
      scopes.map(&:to_sym)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
acts_as_favoritor-4.0.3 lib/acts_as_favoritor/favoritor_lib.rb
acts_as_favoritor-4.0.2 lib/acts_as_favoritor/favoritor_lib.rb
acts_as_favoritor-4.0.1 lib/acts_as_favoritor/favoritor_lib.rb
acts_as_favoritor-4.0.0 lib/acts_as_favoritor/favoritor_lib.rb