Module: ShopifyAPI::DisablePrefixCheck::ClassMethods

Defined in:
lib/shopify_api/disable_prefix_check.rb

Instance Method Summary collapse

Instance Method Details

#check_prefix_options(options) ⇒ Object


7
8
# File 'lib/shopify_api/disable_prefix_check.rb', line 7

def check_prefix_options(options)
end

#conditional_prefix(resource, flexible = false) ⇒ Object

`flexible = true` is hack to allow multiple things through the same AR class


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/shopify_api/disable_prefix_check.rb', line 11

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