Class: Grape::Entity::Condition::HashCondition

Inherits:
Base
  • Object
show all
Defined in:
lib/grape_entity/condition/hash_condition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, #inversed?, #met?, new

Constructor Details

This class inherits a constructor from Grape::Entity::Condition::Base

Instance Attribute Details

#cond_hashObject (readonly)

Returns the value of attribute cond_hash.



7
8
9
# File 'lib/grape_entity/condition/hash_condition.rb', line 7

def cond_hash
  @cond_hash
end

Instance Method Details

#==(other) ⇒ Object



13
14
15
# File 'lib/grape_entity/condition/hash_condition.rb', line 13

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

#if_value(_entity, options) ⇒ Object



17
18
19
# File 'lib/grape_entity/condition/hash_condition.rb', line 17

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

#setup(cond_hash) ⇒ Object



9
10
11
# File 'lib/grape_entity/condition/hash_condition.rb', line 9

def setup(cond_hash)
  @cond_hash = cond_hash
end

#unless_value(_entity, options) ⇒ Object



21
22
23
# File 'lib/grape_entity/condition/hash_condition.rb', line 21

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