Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/hash.rb

Instance Method Summary collapse

Instance Method Details

#to_camelized_graphql_argsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/hash.rb', line 23

def to_camelized_graphql_args
    map do |key, value|
        formatted_value = 
            case value
            when String
                "\"#{value}\""
            when Hash
                value.to_graphql_args
            else
                value
            end

        "#{key.to_s.camelize(:lower)}: #{formatted_value}"
    end.join(", ")
end

#to_graphql_args(enum_friendly: false) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/hash.rb', line 2

def to_graphql_args(enum_friendly: false)
    map do |key, value|
        formatted_value = 
            case value
            when String
                if enum_friendly
                    # uppercase strings wont be wrapped in quotes
                    value.match?(/\A[A-Z_]+\z/) ? value : "\"#{value}\""
                else
                    "\"#{value}\""
                end
            when Hash
                value.to_graphql_args
            else
                value
            end

        "#{key}: #{formatted_value}"
    end.join(", ")
end

#to_shopify_graphql_query_stringObject



39
40
41
42
43
# File 'lib/hash.rb', line 39

def to_shopify_graphql_query_string
    map do |key, value|
        "#{key}:#{value.is_a?(String) ? "\'#{value}\'" : value}"
    end.join(" ")
end