Module: ActiveRecordLazyFindBy

Defined in:
lib/active_record_lazy_find_by.rb,
lib/active_record_lazy_find_by/version.rb

Defined Under Namespace

Modules: Methods

Constant Summary collapse

STATE_METHOD_NAMES =
%i[valid? new_record? persisted?].freeze
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.cacheObject



16
17
18
# File 'lib/active_record_lazy_find_by.rb', line 16

def cache
  @cache ||= {}
end

.module_for(klass, attributes) ⇒ Object



9
10
11
12
13
14
# File 'lib/active_record_lazy_find_by.rb', line 9

def module_for(klass, attributes)
  lazy_attr_names = (klass.attribute_names - attributes.keys.map(&:to_s)).sort
  key = [klass, lazy_attr_names]

  cache[key] ||= build(lazy_attr_names)
end