Sha256: 793cbfc1e865ffd29f41df78acd97b0d3e61f0cb86d70e13898d9029c7f59552

Contents?: true

Size: 762 Bytes

Versions: 2

Compression:

Stored size: 762 Bytes

Contents

module Grape
  class Entity
    module Condition
      class Base
        def self.new(inverse, *args, &block)
          super(inverse).tap { |e| e.setup(*args, &block) }
        end

        def initialize(inverse = false)
          @inverse = inverse
        end

        def ==(other)
          (self.class == other.class) && (inversed? == other.inversed?)
        end

        def inversed?
          @inverse
        end

        def met?(entity, options)
          !@inverse ? if_value(entity, options) : unless_value(entity, options)
        end

        def if_value(_entity, _options)
          raise NotImplementedError
        end

        def unless_value(entity, options)
          !if_value(entity, options)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grape-entity-0.6.1 lib/grape_entity/condition/base.rb
grape-entity-0.6.0 lib/grape_entity/condition/base.rb