Class: DeclarativePolicy::Rule::Not

Inherits:
Base
  • Object
show all
Defined in:
lib/declarative_policy/rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#and, #inspect, make, #negate, #or

Constructor Details

#initialize(rule) ⇒ Not

Returns a new instance of Not.


278
279
280
# File 'lib/declarative_policy/rule.rb', line 278

def initialize(rule)
  @rule = rule
end

Instance Attribute Details

#ruleObject (readonly)

Returns the value of attribute rule


277
278
279
# File 'lib/declarative_policy/rule.rb', line 277

def rule
  @rule
end

Instance Method Details

#cached_pass?(context) ⇒ Boolean

Returns:

  • (Boolean)

295
296
297
298
299
300
301
# File 'lib/declarative_policy/rule.rb', line 295

def cached_pass?(context)
  case @rule.cached_pass?(context)
  when nil then nil
  when true then false
  when false then true
  end
end

#pass?(context) ⇒ Boolean

Returns:

  • (Boolean)

291
292
293
# File 'lib/declarative_policy/rule.rb', line 291

def pass?(context)
  !@rule.pass?(context)
end

#reprObject


307
308
309
# File 'lib/declarative_policy/rule.rb', line 307

def repr
  "~#{@rule.repr}"
end

#score(context) ⇒ Object


303
304
305
# File 'lib/declarative_policy/rule.rb', line 303

def score(context)
  @rule.score(context)
end

#simplifyObject


282
283
284
285
286
287
288
289
# File 'lib/declarative_policy/rule.rb', line 282

def simplify
  case @rule
  when And then Or.new(@rule.rules.map(&:negate)).simplify
  when Or then And.new(@rule.rules.map(&:negate)).simplify
  when Not then @rule.rule.simplify
  else Not.new(@rule.simplify)
  end
end