Shopify / shopify-api-ruby

ShopifyAPI is a lightweight gem for accessing the Shopify admin REST and GraphQL web services.
MIT License
1.06k stars 473 forks source link

ShopifyAPI::Rest::Base#initialize has a from_hash argument but subclasses override it out #1233

Closed eni9889 closed 10 months ago

eni9889 commented 1 year ago

Issue summary

There's a seeminglyl useful from_hash: argument in ShopifyAPI::Rest::Base#initialize, but it's not usable because all subclasses override #initialize.

# base.rb
def initialize(session: nil, from_hash: nil)
   # elided code

  from_hash&.each do |key, value|
    set_property(key, value)
  end
end
# asset.rb
def initialize(session: ShopifyAPI::Context.active_session)
  super(session: session)
  # elided code
end

Expected behavior

Initialize a ShopifyAPI::Rest::* object with #new(from_hash: my_hash)

Actual behavior

ArgumentError: unknown keyword: :from_hash

Steps to reproduce the problem

Specifications

waruboy commented 1 year ago

Up! this function is still featured quite prominently in the latest version of doc: https://github.com/Shopify/shopify-api-ruby/blob/6c2a45f8377ac46217f9dd24068667ccd2a4ee5c/docs/usage/rest.md?plain=1#L51