disable_prefix_check.rb 904 B

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