Class: Omakase::Type
- Inherits:
-
Object
- Object
- Omakase::Type
- Defined in:
- lib/omakase/type.rb
Overview
A return type that is a Ruby class: the model builds the object in code and hands the object itself back, so nothing goes through JSON.
Instance Method Summary collapse
- #definition ⇒ Object (also: #json)
- #describe ⇒ Object
-
#initialize(klass) ⇒ Type
constructor
A new instance of Type.
- #take(value) ⇒ Object
Constructor Details
#initialize(klass) ⇒ Type
Returns a new instance of Type.
7 8 9 |
# File 'lib/omakase/type.rb', line 7 def initialize(klass) @klass = klass end |
Instance Method Details
#definition ⇒ Object Also known as: json
19 20 21 |
# File 'lib/omakase/type.rb', line 19 def definition raise Error, "returns: #{@klass} needs the :code_act strategy — the model has to build the object in code" end |
#describe ⇒ Object
11 |
# File 'lib/omakase/type.rb', line 11 def describe = "a #{@klass}" |
#take(value) ⇒ Object
13 14 15 16 17 |
# File 'lib/omakase/type.rb', line 13 def take(value) return value if value.is_a?(@klass) raise ContractError, "expected #{describe}, got #{value.class}" end |