class ShopifyClient::Base
Attributes
attributes[R]
to_h[R]
to_hash[R]
to_hsh[R]
Public Class Methods
array_from_response(response)
click to toggle source
# File lib/shopify_client/base.rb, line 29 def self.array_from_response(response) parse_array(response[:body]).map do |attributes| new attributes end end
from_response(response)
click to toggle source
# File lib/shopify_client/base.rb, line 25 def self.from_response(response) new parse_single(response[:body]) end
hattr_reader(*attrs)
click to toggle source
Define methods that retrieve the value from an initialized instance variable Hash, using the attribute as a key
# File lib/shopify_client/base.rb, line 10 def self.hattr_reader(*attrs) mod = Module.new do attrs.each do |attribute| define_method attribute do @attributes[attribute.to_sym] end define_method "#{attribute}?" do !!@attributes[attribute.to_sym] end end end const_set(:HashAttributes, mod) include mod end
new(attributes)
click to toggle source
# File lib/shopify_client/base.rb, line 51 def initialize(attributes) @attributes = attributes end
parse_array(body)
click to toggle source
# File lib/shopify_client/base.rb, line 43 def self.parse_array(body) if body body[plural_name] else [] end end
parse_single(body)
click to toggle source
# File lib/shopify_client/base.rb, line 35 def self.parse_single(body) if body body[single_name] else {} end end