disable_prefix_check.rb 993 B

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