Class: Ree::Contracts::CalledArgsValidator
- Defined in:
- lib/ree/contracts/called_args_validator.rb
Defined Under Namespace
Classes: Arg, ArgContract
Instance Attribute Summary collapse
-
#block_contract ⇒ Object
readonly
Returns the value of attribute block_contract.
-
#contracts ⇒ Object
readonly
Returns the value of attribute contracts.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#printed_name ⇒ Object
readonly
Returns the value of attribute printed_name.
Instance Method Summary collapse
- #call(args, kwargs, blk) ⇒ Object
- #get_arg(arg_name) ⇒ Object
- #get_args ⇒ Object
-
#initialize(contract, params, printed_name) ⇒ CalledArgsValidator
constructor
A new instance of CalledArgsValidator.
Constructor Details
#initialize(contract, params, printed_name) ⇒ CalledArgsValidator
Returns a new instance of CalledArgsValidator.
10 11 12 13 14 15 16 17 |
# File 'lib/ree/contracts/called_args_validator.rb', line 10 def initialize(contract, params, printed_name) @contracts = contract.arg_contracts @block_contract = contract.block_contract @params = params @printed_name = printed_name @args = {} build_args end |
Instance Attribute Details
#block_contract ⇒ Object (readonly)
Returns the value of attribute block_contract.
8 9 10 |
# File 'lib/ree/contracts/called_args_validator.rb', line 8 def block_contract @block_contract end |
#contracts ⇒ Object (readonly)
Returns the value of attribute contracts.
8 9 10 |
# File 'lib/ree/contracts/called_args_validator.rb', line 8 def contracts @contracts end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
8 9 10 |
# File 'lib/ree/contracts/called_args_validator.rb', line 8 def params @params end |
#printed_name ⇒ Object (readonly)
Returns the value of attribute printed_name.
8 9 10 |
# File 'lib/ree/contracts/called_args_validator.rb', line 8 def printed_name @printed_name end |
Instance Method Details
#call(args, kwargs, blk) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ree/contracts/called_args_validator.rb', line 27 def call(args, kwargs, blk) if block_contract == ArgContracts::Block && !blk msg = "missing required block" raise ContractError, "Wrong number of arguments for #{printed_name}\n\t - #{msg}" end errors = [] validate_args(args, errors) validate_kwargs(kwargs, errors) return if errors.empty? msg = (errors) puts(colorize(msg)) raise ContractError, msg end |
#get_arg(arg_name) ⇒ Object
23 24 25 |
# File 'lib/ree/contracts/called_args_validator.rb', line 23 def get_arg(arg_name) @args[arg_name] end |
#get_args ⇒ Object
19 20 21 |
# File 'lib/ree/contracts/called_args_validator.rb', line 19 def get_args @args end |