1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
# frozen_string_literal: true
require 'grape_entity/condition/base'
require 'grape_entity/condition/block_condition'
require 'grape_entity/condition/hash_condition'
require 'grape_entity/condition/symbol_condition'
module Grape
class Entity
module Condition
class << self
def new_if(arg)
condition(false, arg)
end
def new_unless(arg)
condition(true, arg)
end
private
def condition(inverse, arg)
condition_klass =
case arg
when Hash then HashCondition
when Proc then BlockCondition
when Symbol then SymbolCondition
end
condition_klass.new(inverse, arg)
end
end
end
end
end
|