Sha256: 5317ae6da65df4ed1b7c1630bcad717023546d63f3518fb6b3d273f997aabcab

Contents?: true

Size: 815 Bytes

Versions: 1

Compression:

Stored size: 815 Bytes

Contents

# frozen_string_literal: true

module ActsAsVotable
  module Extenders
    module Votable
      ALLOWED_CACHEABLE_STRATEGIES = %i[update update_columns]

      def votable?
        false
      end

      def acts_as_votable(args = {})
        include ActsAsVotable::Votable

        if args.key?(:cacheable_strategy) && !ALLOWED_CACHEABLE_STRATEGIES.include?(args[:cacheable_strategy])
          raise ArgumentError, args[:cacheable_strategy]
        end

        define_method :acts_as_votable_options do
          self.class.instance_variable_get("@acts_as_votable_options")
        end

        class_eval do
          @acts_as_votable_options = {
            cacheable_strategy: :update
          }.merge(args)

          def self.votable?
            true
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acts_as_votable-0.14.0 lib/acts_as_votable/extenders/votable.rb