Class: GraphQL::Client::Schema::EnumType::EnumValue

Inherits:
String
  • Object
show all
Defined in:
lib/graphql/client/schema/enum_type.rb

Instance Method Summary collapse

Constructor Details

#initialize(obj, enum_value, enum) ⇒ EnumValue

Returns a new instance of EnumValue.



13
14
15
16
17
# File 'lib/graphql/client/schema/enum_type.rb', line 13

def initialize(obj, enum_value, enum)
  super(obj)
  @enum_value = enum_value
  @enum = enum
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/graphql/client/schema/enum_type.rb', line 31

def method_missing(method_name, *args)
  if method_name[-1] == "?"
    queried_value = method_name[0..-2]
    if @enum.include?(queried_value)
      raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0)" unless args.empty?
      return @enum_value == queried_value
    end
  end

  super
end

Instance Method Details

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/graphql/client/schema/enum_type.rb', line 23

def respond_to_missing?(method_name, include_private = false)
  if method_name[-1] == "?" && @enum.include?(method_name[0..-2])
    true
  else
    super
  end
end

#unknown_enum_value?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/graphql/client/schema/enum_type.rb', line 19

def unknown_enum_value?
  false
end