Sha256: f3a5ed8a95c8a2096eb22f7c2f3e5db7dc17aa87194102e2fbca4581c46a33d4

Contents?: true

Size: 938 Bytes

Versions: 8

Compression:

Stored size: 938 Bytes

Contents

# frozen_string_literal: true

module ActsAsRecursiveTree
  module Options
    class DepthCondition
      def ==(other)
        @value     = Values.create(other)
        @operation = true
      end

      def !=(other)
        @value     = Values.create(other)
        @operation = false
      end

      def <(other)
        @value     = other
        @operation = :lt
      end

      def <=(other)
        @value     = other
        @operation = :lteq
      end

      def >(other)
        @value     = other
        @operation = :gt
      end

      def >=(other)
        @value     = other
        @operation = :gteq
      end

      def apply_to(attribute)
        if @value.is_a?(Values::Base)
          if @operation
            @value.apply_to(attribute)
          else
            @value.apply_negated_to(attribute)
          end
        else
          attribute.send(@operation, @value)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
acts_as_recursive_tree-4.1.0 lib/acts_as_recursive_tree/options/depth_condition.rb
acts_as_recursive_tree-4.0.0 lib/acts_as_recursive_tree/options/depth_condition.rb
acts_as_recursive_tree-3.5.0 lib/acts_as_recursive_tree/options/depth_condition.rb
acts_as_recursive_tree-3.4.0 lib/acts_as_recursive_tree/options/depth_condition.rb
acts_as_recursive_tree-3.3.0 lib/acts_as_recursive_tree/options/depth_condition.rb
acts_as_recursive_tree-3.2.0 lib/acts_as_recursive_tree/options/depth_condition.rb
acts_as_recursive_tree-3.1.0 lib/acts_as_recursive_tree/options/depth_condition.rb
acts_as_recursive_tree-3.0.0 lib/acts_as_recursive_tree/options/depth_condition.rb