Sha256: e3ae6850c11f0b776ed7ee47fac3c3532bea8f1988a7e01560c516dbb488e5f3

Contents?: true

Size: 879 Bytes

Versions: 3

Compression:

Stored size: 879 Bytes

Contents

# frozen_string_literal: true

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

      def votable?
        false
      end

      def acts_as_votable(args = {})
        require "acts_as_votable/votable"
        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_attributes
          }.merge(args)

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
acts_as_votable-0.12.0 lib/acts_as_votable/extenders/votable.rb
acts_as_votable-0.11.1 lib/acts_as_votable/extenders/votable.rb
acts_as_votable-0.11.0 lib/acts_as_votable/extenders/votable.rb