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.



282
283
284
# File 'lib/declarative_policy/rule.rb', line 282

def initialize(rule)
  @rule = rule
end

Instance Attribute Details

#ruleObject (readonly)

Returns the value of attribute rule.



280
281
282
# File 'lib/declarative_policy/rule.rb', line 280

def rule
  @rule
end

Instance Method Details

#cached_pass?(context) ⇒ Boolean

Returns:

  • (Boolean)


299
300
301
302
303
304
305
# File 'lib/declarative_policy/rule.rb', line 299

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)


295
296
297
# File 'lib/declarative_policy/rule.rb', line 295

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

#reprObject



311
312
313
# File 'lib/declarative_policy/rule.rb', line 311

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

#score(context) ⇒ Object



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

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

#simplifyObject



286
287
288
289
290
291
292
293
# File 'lib/declarative_policy/rule.rb', line 286

def simplify
  case @rule
  when And then Or.new(@rule.rules.map(&:negate)).simplify # DeMorgan's laws
  when Or then And.new(@rule.rules.map(&:negate)).simplify # DeMorgan's laws
  when Not then @rule.rule.simplify # double negation
  else Not.new(@rule.simplify)
  end
end