Class: FiberAudit::Runtime::Sampler
- Inherits:
-
Object
- Object
- FiberAudit::Runtime::Sampler
- Defined in:
- lib/fiber_audit/runtime/sampler.rb
Constant Summary collapse
- RANDOM_SOURCE =
-> { Random.rand }.freeze
Instance Attribute Summary collapse
-
#policy ⇒ Object
readonly
Returns the value of attribute policy.
Instance Method Summary collapse
-
#initialize(policy:, random: RANDOM_SOURCE) ⇒ Sampler
constructor
A new instance of Sampler.
- #sample? ⇒ Boolean
Constructor Details
#initialize(policy:, random: RANDOM_SOURCE) ⇒ Sampler
Returns a new instance of Sampler.
12 13 14 15 16 17 18 19 |
# File 'lib/fiber_audit/runtime/sampler.rb', line 12 def initialize(policy:, random: RANDOM_SOURCE) raise RuntimeContractError, 'policy must be a FiberAudit::Runtime::Policy' unless policy.is_a?(Policy) raise RuntimeContractError, 'random source must respond to call' unless random.respond_to?(:call) @policy = policy @random = random freeze end |
Instance Attribute Details
#policy ⇒ Object (readonly)
Returns the value of attribute policy.
10 11 12 |
# File 'lib/fiber_audit/runtime/sampler.rb', line 10 def policy @policy end |
Instance Method Details
#sample? ⇒ Boolean
21 22 23 |
# File 'lib/fiber_audit/runtime/sampler.rb', line 21 def sample? policy.sample?(draw: @random.call) end |