Sha256: 470e8bd103d11122ef753189dbd6a44fa5fe619847cb5a657bae97e9620b5f13
Contents?: true
Size: 869 Bytes
Versions: 2
Compression:
Stored size: 869 Bytes
Contents
# frozen_string_literal: true module GraphQL module Client module Deserialization private def create_accessor_methods(field_name, graph_object) define_singleton_method(field_name) do ivar_name = "@#{field_name}" if instance_variable_defined?(ivar_name) instance_variable_get(ivar_name) else instance_variable_set(ivar_name, graph_object) end end underscored_name = underscore(field_name) if field_name != underscored_name define_singleton_method(underscored_name) { send field_name } end end def underscore(name) name .gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_') .downcase end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
graphql_client-0.4.1 | lib/graphql_client/deserialization.rb |
graphql_client-0.3.3 | lib/graphql_client/deserialization.rb |