Class: Kindergarten::StrictGoverness
- Inherits:
-
HeadGoverness
- Object
- HeadGoverness
- Kindergarten::StrictGoverness
- Defined in:
- lib/kindergarten/governesses/strict_governess.rb
Overview
Note:
Does not specify how to rollback when the guard method was not called, You’re on your own there…
A very strict governess, forces all the sandbox methods to use the guard methods.
Instance Attribute Summary collapse
-
#guard_count ⇒ Object
readonly
Check how often the perimeter guarded something.
Attributes inherited from HeadGoverness
Instance Method Summary collapse
-
#governed(method, &block) ⇒ Object
Force the use of guard inside sandbox methods.
-
#guard(*args) ⇒ Object
guard something and increment the guard count.
-
#initialize(child) ⇒ StrictGoverness
constructor
A new instance of StrictGoverness.
-
#unguarded(&block) ⇒ Object
allow something unguarded and increment the guard count.
Methods inherited from HeadGoverness
#empty?, #guarded?, #rinse, #scrub, #unguarded?
Constructor Details
#initialize(child) ⇒ StrictGoverness
Returns a new instance of StrictGoverness.
13 14 15 16 |
# File 'lib/kindergarten/governesses/strict_governess.rb', line 13 def initialize(child) super @guard_count = 0 end |
Instance Attribute Details
#guard_count ⇒ Object (readonly)
Check how often the perimeter guarded something
11 12 13 |
# File 'lib/kindergarten/governesses/strict_governess.rb', line 11 def guard_count @guard_count end |
Instance Method Details
#governed(method, &block) ⇒ Object
Force the use of guard inside sandbox methods
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kindergarten/governesses/strict_governess.rb', line 23 def governed(method, &block) before = self.guard_count res = yield if @unguarded != true && self.guard_count == before raise Kindergarten::Perimeter::Unguarded.new( "#{method} was executed without propper guarding" ) end return res end |
#guard(*args) ⇒ Object
guard something and increment the guard count
37 38 39 40 |
# File 'lib/kindergarten/governesses/strict_governess.rb', line 37 def guard(*args) @guard_count += 1 super end |
#unguarded(&block) ⇒ Object
allow something unguarded and increment the guard count
43 44 45 46 |
# File 'lib/kindergarten/governesses/strict_governess.rb', line 43 def unguarded(&block) @guard_count += 1 super end |