Class: GraphWeaver::Codegen::EnumNode
- Inherits:
-
Object
- Object
- GraphWeaver::Codegen::EnumNode
- Defined in:
- lib/graph_weaver/codegen/nodes.rb
Instance Attribute Summary collapse
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #bare_type ⇒ Object
- #cast(expr, _depth) ⇒ Object
- #coerce(expr) ⇒ Object
-
#coerce? ⇒ Boolean
enums always coerce: a kwarg or hash field accepts the T::Enum or its wire value (deserialize raises on anything else).
- #coerce_input_type ⇒ Object
- #hash_coerce(expr, _depth) ⇒ Object
- #hash_coerce_identity? ⇒ Boolean
- #identity? ⇒ Boolean
-
#initialize(class_name, values) ⇒ EnumNode
constructor
A new instance of EnumNode.
- #nested ⇒ Object
- #non_null? ⇒ Boolean
- #prop_type ⇒ Object
- #serialize(expr, _depth) ⇒ Object
- #serialize_identity? ⇒ Boolean
Constructor Details
#initialize(class_name, values) ⇒ EnumNode
Returns a new instance of EnumNode.
172 173 174 175 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 172 def initialize(class_name, values) @class_name = class_name @values = values end |
Instance Attribute Details
#class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
170 171 172 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 170 def class_name @class_name end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
170 171 172 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 170 def values @values end |
Instance Method Details
#bare_type ⇒ Object
177 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 177 def = class_name |
#cast(expr, _depth) ⇒ Object
183 184 185 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 183 def cast(expr, _depth) "#{class_name}.deserialize(#{expr})" end |
#coerce(expr) ⇒ Object
199 200 201 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 199 def coerce(expr) "(#{expr}.is_a?(#{class_name}) ? #{expr} : #{class_name}.deserialize(#{expr}))" end |
#coerce? ⇒ Boolean
enums always coerce: a kwarg or hash field accepts the T::Enum or its wire value (deserialize raises on anything else)
197 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 197 def coerce? = true |
#coerce_input_type ⇒ Object
203 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 203 def coerce_input_type = "T.any(#{class_name}, String)" |
#hash_coerce(expr, _depth) ⇒ Object
204 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 204 def hash_coerce(expr, _depth) = coerce(expr) |
#hash_coerce_identity? ⇒ Boolean
205 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 205 def hash_coerce_identity? = false |
#identity? ⇒ Boolean
187 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 187 def identity? = false |
#nested ⇒ Object
207 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 207 def nested = self |
#non_null? ⇒ Boolean
206 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 206 def non_null? = false |
#prop_type ⇒ Object
179 180 181 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 179 def prop_type "T.nilable(#{})" end |
#serialize(expr, _depth) ⇒ Object
189 190 191 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 189 def serialize(expr, _depth) "#{expr}.serialize" end |
#serialize_identity? ⇒ Boolean
193 |
# File 'lib/graph_weaver/codegen/nodes.rb', line 193 def serialize_identity? = false |