Class: SimpleContracts::Base
- Inherits:
-
Object
- Object
- SimpleContracts::Base
- Defined in:
- lib/simple_contracts/base.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object (also: #match!)
- #contract_name ⇒ Object
- #deserialize(state_dump) ⇒ Object
-
#initialize(*args, async: nil, logger: nil, sampler: nil, stats: nil, **kwargs) ⇒ Base
constructor
A new instance of Base.
- #serialize ⇒ Object
Constructor Details
#initialize(*args, async: nil, logger: nil, sampler: nil, stats: nil, **kwargs) ⇒ Base
Returns a new instance of Base.
57 58 59 60 61 62 63 64 |
# File 'lib/simple_contracts/base.rb', line 57 def initialize(*args, async: nil, logger: nil, sampler: nil, stats: nil, **kwargs) @async = async.nil? ? default_async : !!async @sampler = sampler @stats = stats @logger = logger @input = {args: args, kwargs: kwargs} = {checked: [], input: @input} end |
Class Method Details
.call(*args, **kwargs) ⇒ Object
33 34 35 |
# File 'lib/simple_contracts/base.rb', line 33 def call(*args, **kwargs) new(*args, **kwargs).call { yield } end |
.expectations_methods ⇒ Object
41 42 43 |
# File 'lib/simple_contracts/base.rb', line 41 def expectations_methods @expectations_methods ||= methods_with_prefix("expect_") end |
.guarantees_methods ⇒ Object
37 38 39 |
# File 'lib/simple_contracts/base.rb', line 37 def guarantees_methods @guarantees_methods ||= methods_with_prefix("guarantee_") end |
Instance Method Details
#call ⇒ Object Also known as: match!
66 67 68 69 70 71 |
# File 'lib/simple_contracts/base.rb', line 66 def call return yield unless enabled? @output = yield @async ? verify_async : verify @output end |
#contract_name ⇒ Object
83 84 85 |
# File 'lib/simple_contracts/base.rb', line 83 def contract_name self.class.name end |
#deserialize(state_dump) ⇒ Object
79 80 81 |
# File 'lib/simple_contracts/base.rb', line 79 def deserialize(state_dump) Marshal.load(state_dump) end |
#serialize ⇒ Object
75 76 77 |
# File 'lib/simple_contracts/base.rb', line 75 def serialize Marshal.dump(input: @input, output: @output, meta: ) end |