Sha256: 7d6102ddbb014784dd354aca133bb6a5d6b9c5cd342ae1c716d30191755b479b

Contents?: true

Size: 1.07 KB

Versions: 29

Compression:

Stored size: 1.07 KB

Contents

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 :prefix do |options = {}|
        resource_type =  options[resource] if flexible

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

      define_singleton_method :instantiate_record do |record, prefix_options = {}|
        new_record(record).tap do |resource|
          resource.prefix_options = prefix_options unless prefix_options.blank?
        end
      end
    end

    def new_record(record)
      if ActiveSupport::VERSION::MAJOR == 3 && ActiveSupport::VERSION::MINOR == 0
        new(record)
      else
        new(record, true)
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
shopify_api-6.0.0 lib/active_resource/disable_prefix_check.rb
shopify_api-5.2.4 lib/active_resource/disable_prefix_check.rb
shopify_api-5.2.3 lib/active_resource/disable_prefix_check.rb
shopify_api-5.2.2 lib/active_resource/disable_prefix_check.rb
shopify_api-5.2.1 lib/active_resource/disable_prefix_check.rb
shopify_api-5.2.0 lib/active_resource/disable_prefix_check.rb
shopify_api-5.1.0 lib/active_resource/disable_prefix_check.rb
shopify_api-5.0.0 lib/active_resource/disable_prefix_check.rb
shopify_api-4.13.0 lib/active_resource/disable_prefix_check.rb
shopify_api-4.12.0 lib/active_resource/disable_prefix_check.rb
shopify_api-4.11.0 lib/active_resource/disable_prefix_check.rb
shopify_api-4.10.0 lib/active_resource/disable_prefix_check.rb
shopify_api-4.9.1 lib/active_resource/disable_prefix_check.rb
shopify_api-4.9.0 lib/active_resource/disable_prefix_check.rb
shopify_api-4.8.0 lib/active_resource/disable_prefix_check.rb
shopify_api-4.7.1 lib/active_resource/disable_prefix_check.rb
shopify_api-4.7.0 lib/active_resource/disable_prefix_check.rb
shopify_api-4.6.0 lib/active_resource/disable_prefix_check.rb
shopify_api-4.5.0 lib/active_resource/disable_prefix_check.rb
shopify_api-4.4.0 lib/active_resource/disable_prefix_check.rb