module WCC::Contentful::ActiveRecordShim
Public Instance Methods
attributes()
click to toggle source
# File lib/wcc/contentful/active_record_shim.rb, line 6 def attributes @attributes ||= to_h['fields'].tap { |fields| fields['id'] = id } end
cache_key()
click to toggle source
# File lib/wcc/contentful/active_record_shim.rb, line 10 def cache_key return cache_key_with_version unless ActiveRecord::Base.try(:cache_versioning) == true "#{self.class.model_name}/#{id}" end
cache_key_with_version()
click to toggle source
# File lib/wcc/contentful/active_record_shim.rb, line 16 def cache_key_with_version "#{self.class.model_name}/#{id}-#{cache_version}" end
cache_version()
click to toggle source
# File lib/wcc/contentful/active_record_shim.rb, line 20 def cache_version sys.revision.to_s end
const_get(name)
click to toggle source
Calls superclass method
# File lib/wcc/contentful/active_record_shim.rb, line 35 def const_get(name) # Because our pattern is `class MyModel < WCC::Contentful::Model::MyModel` # if you do MyModel.const_get('MyModel') Algolia expects you to return # ::MyModel not WCC::Contentful::Model::MyModel return self if name == model_name super end
find_in_batches(options, &block)
click to toggle source
# File lib/wcc/contentful/active_record_shim.rb, line 52 def find_in_batches(options, &block) options ||= {} batch_size = options.delete(:batch_size) || 1000 filter = { options: { limit: batch_size, skip: options.delete(:start) || 0, include: options.delete(:include) || 1 } } find_all(filter).each_slice(batch_size, &block) end
model_name()
click to toggle source
# File lib/wcc/contentful/active_record_shim.rb, line 31 def model_name WCC::Contentful::Helpers.constant_from_content_type(content_type) end
table_name()
click to toggle source
# File lib/wcc/contentful/active_record_shim.rb, line 44 def table_name model_name.tableize end
unscoped() { || ... }
click to toggle source
# File lib/wcc/contentful/active_record_shim.rb, line 48 def unscoped yield end
where(**conditions)
click to toggle source
# File lib/wcc/contentful/active_record_shim.rb, line 66 def where(**conditions) # TODO: return a Query object that implements more of the ActiveRecord query interface # https://guides.rubyonrails.org/active_record_querying.html#conditions find_all(conditions) end