Class: GlobalID::Locator::BaseLocator

Inherits:
Object
  • Object
show all
Defined in:
lib/global_id/locator.rb

Direct Known Subclasses

UnscopedLocator

Instance Method Summary collapse

Instance Method Details

#locate(gid) ⇒ Object


129
130
131
# File 'lib/global_id/locator.rb', line 129

def locate(gid)
  gid.model_class.find gid.model_id
end

#locate_many(gids, options = {}) ⇒ Object


133
134
135
136
137
138
139
140
141
# File 'lib/global_id/locator.rb', line 133

def locate_many(gids, options = {})
  models_and_ids  = gids.collect { |gid| [ gid.model_class, gid.model_id ] }
  ids_by_model    = models_and_ids.group_by(&:first)
  loaded_by_model = Hash[ids_by_model.map { |model, ids|
    [ model, find_records(model, ids.map(&:last), ignore_missing: options[:ignore_missing]).index_by { |record| record.id.to_s } ]
  }]

  models_and_ids.collect { |(model, id)| loaded_by_model[model][id] }.compact
end