Module: ActiveShopifyGraphQL::GidHelper
- Defined in:
- lib/active_shopify_graphql/gid_helper.rb
Overview
Helper module for handling Shopify Global IDs (GIDs) Provides utilities for parsing and building GIDs according to the URI::GID standard
Class Method Summary collapse
-
.normalize_gid(id, model_name) ⇒ String
Normalize an ID value to a proper Shopify GID format If the ID is already a valid GID, returns it as-is Otherwise, builds a new GID using the provided model name.
-
.valid_gid?(value) ⇒ Boolean
Check if a value is a valid Shopify GID.
Class Method Details
.normalize_gid(id, model_name) ⇒ String
Normalize an ID value to a proper Shopify GID format If the ID is already a valid GID, returns it as-is Otherwise, builds a new GID using the provided model name
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/active_shopify_graphql/gid_helper.rb', line 24 def self.normalize_gid(id, model_name) # Check if id is already a valid GID begin parsed_gid = URI::GID.parse(id) return id if parsed_gid rescue URI::InvalidURIError, URI::BadURIError, ArgumentError # Not a valid GID, proceed to build one end # Build GID from the provided ID and model name URI::GID.build(app: "shopify", model_name: model_name, model_id: id).to_s end |
.valid_gid?(value) ⇒ Boolean
Check if a value is a valid Shopify GID
49 50 51 52 53 54 |
# File 'lib/active_shopify_graphql/gid_helper.rb', line 49 def self.valid_gid?(value) URI::GID.parse(value) true rescue URI::InvalidURIError, URI::BadURIError, ArgumentError false end |