Class: GraphQL::Client::QueryResult::ListWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/client/query_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ ListWrapper

Returns a new instance of ListWrapper.



103
104
105
# File 'lib/graphql/client/query_result.rb', line 103

def initialize(type)
  @of_klass = type
end

Instance Attribute Details

#of_klassObject (readonly)

Returns the value of attribute of_klass.



101
102
103
# File 'lib/graphql/client/query_result.rb', line 101

def of_klass
  @of_klass
end

Instance Method Details

#cast(value, errors) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/graphql/client/query_result.rb', line 107

def cast(value, errors)
  case value
  when Array
    List.new(value.each_with_index.map { |e, idx|
      @of_klass.cast(e, errors.filter_by_path(idx))
    }, errors)
  when NilClass
    nil
  else
    raise ArgumentError, "expected list value to be an Array, but was #{value.class}"
  end
end

#|(other) ⇒ Object



120
121
122
123
124
125
126
# File 'lib/graphql/client/query_result.rb', line 120

def |(other)
  if self.class == other.class
    self.of_klass | other.of_klass
  else
    raise TypeError, "expected other to be a #{self.class}"
  end
end