Class: Typedocs::MethodSpec::Single
- Inherits:
-
Object
- Object
- Typedocs::MethodSpec::Single
- Defined in:
- lib/typedocs/method_spec.rb
Instance Attribute Summary collapse
-
#arguments_spec ⇒ Object
readonly
Returns the value of attribute arguments_spec.
-
#block_spec ⇒ Object
readonly
Returns the value of attribute block_spec.
-
#retval_spec ⇒ Object
readonly
Returns the value of attribute retval_spec.
Instance Method Summary collapse
- #call_with_validate(method, *args, &block) ⇒ Object
-
#initialize(args_spec, block_spec, retval_spec) ⇒ Single
constructor
A new instance of Single.
- #to_source ⇒ Object
- #validate_args(args) ⇒ Object
- #validate_block(block) ⇒ Object
- #validate_caller(args, block) ⇒ Object
- #validate_retval(ret) ⇒ Object
Constructor Details
#initialize(args_spec, block_spec, retval_spec) ⇒ Single
Returns a new instance of Single.
38 39 40 41 42 43 44 45 |
# File 'lib/typedocs/method_spec.rb', line 38 def initialize(args_spec, block_spec, retval_spec) Typedocs.ensure_klass(args_spec, Typedocs::ArgumentsSpec) Typedocs.ensure_klass(block_spec, Typedocs::BlockSpec) Typedocs.ensure_klass(retval_spec, Typedocs::TypeSpec) @arguments_spec = args_spec @block_spec = block_spec @retval_spec = retval_spec end |
Instance Attribute Details
#arguments_spec ⇒ Object (readonly)
Returns the value of attribute arguments_spec.
47 48 49 |
# File 'lib/typedocs/method_spec.rb', line 47 def arguments_spec @arguments_spec end |
#block_spec ⇒ Object (readonly)
Returns the value of attribute block_spec.
48 49 50 |
# File 'lib/typedocs/method_spec.rb', line 48 def block_spec @block_spec end |
#retval_spec ⇒ Object (readonly)
Returns the value of attribute retval_spec.
49 50 51 |
# File 'lib/typedocs/method_spec.rb', line 49 def retval_spec @retval_spec end |
Instance Method Details
#call_with_validate(method, *args, &block) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/typedocs/method_spec.rb', line 51 def call_with_validate(method, *args, &block) validate_args args validate_block block ret = method.call *args, &block validate_retval ret ret end |
#to_source ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/typedocs/method_spec.rb', line 79 def to_source s = '' s << arguments_spec.to_source s << " -> " unless arguments_spec.empty? s << block_spec.to_source_with_arrow s << "#{retval_spec.to_source}" end |
#validate_args(args) ⇒ Object
64 65 66 |
# File 'lib/typedocs/method_spec.rb', line 64 def validate_args(args) raise Typedocs::ArgumentError, arguments_spec.(args) unless arguments_spec.valid?(args) end |
#validate_block(block) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/typedocs/method_spec.rb', line 68 def validate_block(block) raise Typedocs::BlockError, "Cant accept block" if !block_spec && block if block_spec raise Typedocs::BlockError, block_spec.(block) unless block_spec.valid?(block) end end |
#validate_caller(args, block) ⇒ Object
59 60 61 62 |
# File 'lib/typedocs/method_spec.rb', line 59 def validate_caller(args, block) validate_args args validate_block block end |
#validate_retval(ret) ⇒ Object
75 76 77 |
# File 'lib/typedocs/method_spec.rb', line 75 def validate_retval(ret) raise Typedocs::RetValError, retval_spec.(ret) unless retval_spec.valid?(ret) end |