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.



11
12
13
# File 'lib/grape_entity/condition/base.rb', line 11

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

Class Method Details

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



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

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

Instance Method Details

#==(other) ⇒ Object



15
16
17
# File 'lib/grape_entity/condition/base.rb', line 15

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

#if_value(_entity, _options) ⇒ Object

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/grape_entity/condition/base.rb', line 27

def if_value(_entity, _options)
  raise NotImplementedError
end

#inversed?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/grape_entity/condition/base.rb', line 19

def inversed?
  @inverse
end

#met?(entity, options) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/grape_entity/condition/base.rb', line 23

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

#unless_value(entity, options) ⇒ Object



31
32
33
# File 'lib/grape_entity/condition/base.rb', line 31

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