disable_prefix_check.rb 1020 B

12345678910111213141516171819202122232425262728293031
  1. # frozen_string_literal: true
  2. module ShopifyAPI
  3. module DisablePrefixCheck
  4. extend ActiveSupport::Concern
  5. module ClassMethods
  6. def check_prefix_options(options)
  7. end
  8. # `flexible = true` is hack to allow multiple things through the same AR class
  9. def conditional_prefix(resource, flexible = false)
  10. resource_id = "#{resource}_id".to_sym
  11. resource_type = flexible ? ":#{resource}" : resource.to_s.pluralize
  12. init_prefix_explicit(resource_type, resource_id)
  13. define_singleton_method(:resource_prefix) do |options = {}|
  14. resource_type = options[resource] if flexible
  15. options[resource_id].nil? ? '' : "#{resource_type}/#{options[resource_id]}/"
  16. end
  17. define_singleton_method(:instantiate_record) do |record, prefix_options = {}|
  18. new(record, true).tap do |resource_instance|
  19. resource_instance.prefix_options = prefix_options unless prefix_options.blank?
  20. end
  21. end
  22. end
  23. end
  24. end
  25. end