Class: Grape::Entity::Condition::Base

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

Direct Known Subclasses

BlockCondition, HashCondition, SymbolCondition

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inverse = false) ⇒ Base

Returns a new instance of Base.



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

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

Class Method Details

.new(inverse, *args, &block) ⇒ Object



5
6
7
# File 'lib/grape_entity/condition/base.rb', line 5

def self.new(inverse, *args, &block)
  super(inverse).tap { |e| e.setup(*args, &block) }
end

Instance Method Details

#==(other) ⇒ Object



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

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

#if_value(_entity, _options) ⇒ Object



25
26
27
# File 'lib/grape_entity/condition/base.rb', line 25

def if_value(_entity, _options)
  fail NotImplementedError
end

#inversed?Boolean

Returns:

  • (Boolean)


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

def inversed?
  @inverse
end

#met?(entity, options) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#unless_value(entity, options) ⇒ Object



29
30
31
# File 'lib/grape_entity/condition/base.rb', line 29

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