From 8caa1a4f0759fe34fbdf34ed6fd0984a026e978b Mon Sep 17 00:00:00 2001 From: Paulo Margarido Date: Tue, 4 Aug 2020 09:47:37 -0400 Subject: [PATCH] Make schema.get_shop a class method --- lib/shopify-cli/admin_api/schema.rb | 38 +++++++++++++++-------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/lib/shopify-cli/admin_api/schema.rb b/lib/shopify-cli/admin_api/schema.rb index 9332fd098d..7bbf40c387 100644 --- a/lib/shopify-cli/admin_api/schema.rb +++ b/lib/shopify-cli/admin_api/schema.rb @@ -3,16 +3,27 @@ module ShopifyCli class AdminAPI class Schema < Hash - def self.get(ctx) - unless ShopifyCli::DB.exists?(:shopify_admin_schema) - shop = Project.current.env.shop || get_shop(@ctx) - schema = AdminAPI.query(ctx, 'admin_introspection', shop: shop) - ShopifyCli::DB.set(shopify_admin_schema: JSON.dump(schema)) + class << self + def get(ctx) + unless ShopifyCli::DB.exists?(:shopify_admin_schema) + shop = Project.current.env.shop || get_shop(ctx) + schema = AdminAPI.query(ctx, 'admin_introspection', shop: shop) + ShopifyCli::DB.set(shopify_admin_schema: JSON.dump(schema)) + end + # This is ruby magic for making a new hash with another hash. + # It wraps the JSON in our Schema Class to have the helper methods + # available + self[JSON.parse(ShopifyCli::DB.get(:shopify_admin_schema))] + end + + private + + def get_shop(ctx) + res = ShopifyCli::Tasks::SelectOrgAndShop.call(ctx) + domain = res[:shop_domain] + Project.current.env.update(ctx, :shop, domain) + domain end - # This is ruby magic for making a new hash with another hash. - # It wraps the JSON in our Schema Class to have the helper methods - # available - self[JSON.parse(ShopifyCli::DB.get(:shopify_admin_schema))] end def type(name) @@ -28,15 +39,6 @@ def get_names_from_type(name) object["name"] end end - - private - - def get_shop(ctx) - res = ShopifyCli::Tasks::SelectOrgAndShop.call(ctx) - domain = res[:shop_domain] - Project.current.env.update(ctx, :shop, domain) - domain - end end end end