Class: GraphQL::GraphQLEnumType
Overview
Instance Method Summary
collapse
#!
#+@
configuration, configure_with, #initialize, #method_missing, new
Instance Method Details
#parse_literal(ast) ⇒ Object
91
92
93
|
# File 'lib/graphql/type/enum_type.rb', line 91
def parse_literal(ast)
value(ast[:value]).value rescue nil if ast[:kind] == :enum
end
|
#parse_value(v) ⇒ Object
87
88
89
|
# File 'lib/graphql/type/enum_type.rb', line 87
def parse_value(v)
value(v).value rescue nil
end
|
#serialize(v) ⇒ Object
83
84
85
|
# File 'lib/graphql/type/enum_type.rb', line 83
def serialize(v)
value_map_by_values[v.to_s].name rescue nil
end
|
#to_s ⇒ Object
95
96
97
|
# File 'lib/graphql/type/enum_type.rb', line 95
def to_s
name
end
|
#value(name) ⇒ Object
79
80
81
|
# File 'lib/graphql/type/enum_type.rb', line 79
def value(name)
value_map[name.to_sym]
end
|
#value_map ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/graphql/type/enum_type.rb', line 59
def value_map
@value_map ||= @configuration.values.reduce({}) do |memo, value|
value.value = value.name if value.value.nil?
memo[value.name.to_sym] = value
memo
end
end
|
#value_map_by_values ⇒ Object
67
68
69
|
# File 'lib/graphql/type/enum_type.rb', line 67
def value_map_by_values
@value_map_by_values ||= values.reduce({}) { |memo, value| memo[value.value.to_s] = value ; memo }
end
|
#value_names ⇒ Object
71
72
73
|
# File 'lib/graphql/type/enum_type.rb', line 71
def value_names
@value_names ||= value_map.keys
end
|
#values ⇒ Object
75
76
77
|
# File 'lib/graphql/type/enum_type.rb', line 75
def values
@values ||= value_map.values
end
|