Sha256: df65a2dc29f71dcc2cac83decefabebb8d19e9c4a50b3960b78523324ff896ce

Contents?: true

Size: 559 Bytes

Versions: 11

Compression:

Stored size: 559 Bytes

Contents

# frozen_string_literal: true

module Grape
  class Entity
    module Condition
      class HashCondition < Base
        attr_reader :cond_hash

        def setup(cond_hash)
          @cond_hash = cond_hash
        end

        def ==(other)
          super && @cond_hash == other.cond_hash
        end

        def if_value(_entity, options)
          @cond_hash.all? { |k, v| options[k.to_sym] == v }
        end

        def unless_value(_entity, options)
          @cond_hash.any? { |k, v| options[k.to_sym] != v }
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
grape-entity-1.0.1 lib/grape_entity/condition/hash_condition.rb
grape-entity-1.0.0 lib/grape_entity/condition/hash_condition.rb
grape-entity-0.10.2 lib/grape_entity/condition/hash_condition.rb
grape-entity-0.10.1 lib/grape_entity/condition/hash_condition.rb
grape-entity-0.10.0 lib/grape_entity/condition/hash_condition.rb
grape-entity-0.9.0 lib/grape_entity/condition/hash_condition.rb
grape-entity-0.8.2 lib/grape_entity/condition/hash_condition.rb
grape-entity-0.8.1 lib/grape_entity/condition/hash_condition.rb
grape-entity-0.8.0 lib/grape_entity/condition/hash_condition.rb
grape-entity-0.7.1 lib/grape_entity/condition/hash_condition.rb
grape-entity-0.7.0 lib/grape_entity/condition/hash_condition.rb