Sha256: bb17953abfa0e05b363ae9fbcc9c885595bf34fc9209ab5bdf72aa176824c551

Contents?: true

Size: 1020 Bytes

Versions: 8

Compression:

Stored size: 1020 Bytes

Contents

# frozen_string_literal: true
module ShopifyAPI
  module DisablePrefixCheck
    extend ActiveSupport::Concern

    module ClassMethods
      def check_prefix_options(options)
      end

      # `flexible = true` is hack to allow multiple things through the same AR class
      def conditional_prefix(resource, flexible = false)
        resource_id = "#{resource}_id".to_sym
        resource_type = flexible ? ":#{resource}" : resource.to_s.pluralize

        init_prefix_explicit(resource_type, resource_id)

        define_singleton_method(:resource_prefix) do |options = {}|
          resource_type = options[resource] if flexible

          options[resource_id].nil? ? '' : "#{resource_type}/#{options[resource_id]}/"
        end

        define_singleton_method(:instantiate_record) do |record, prefix_options = {}|
          new(record, true).tap do |resource_instance|
            resource_instance.prefix_options = prefix_options unless prefix_options.blank?
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
ruby_shopify_api-1.2.0 lib/ruby_shopify_api/disable_prefix_check.rb
ruby_shopify_api-1.1.0 lib/shopify_api/disable_prefix_check.rb
ruby_shopify_api-1.0.0 lib/shopify_api/disable_prefix_check.rb
shopify_api-9.5.1 lib/shopify_api/disable_prefix_check.rb
shopify_api-9.5 lib/shopify_api/disable_prefix_check.rb
shopify_api-9.4.1 lib/shopify_api/disable_prefix_check.rb
shopify_api-9.4.0 lib/shopify_api/disable_prefix_check.rb
shopify_api-9.3.0 lib/shopify_api/disable_prefix_check.rb