Module: FrozenRecord::Compact::ClassMethods

Defined in:
lib/frozen_record/compact.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_attributes_cacheObject (readonly)

Returns the value of attribute _attributes_cache.



32
33
34
# File 'lib/frozen_record/compact.rb', line 32

def _attributes_cache
  @_attributes_cache
end

Instance Method Details

#define_method_attribute(attr) ⇒ Object



28
29
30
# File 'lib/frozen_record/compact.rb', line 28

def define_method_attribute(attr, **)
  generated_attribute_methods.attr_reader(attr)
end

#load_records(force: false) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/frozen_record/compact.rb', line 8

def load_records(force: false)
  if force || (auto_reloading && file_changed?)
    @records = nil
    undefine_attribute_methods
  end

  @records ||= begin
    records = backend.load(file_path)
    if default_attributes
      records = records.map { |r| assign_defaults!(r.dup).freeze }.freeze
    end
    @attributes = list_attributes(records).freeze
    build_attributes_cache
    define_attribute_methods(@attributes.to_a)
    records = records.map { |r| load(r) }.freeze
    index_definitions.values.each { |index| index.build(records) }
    records
  end
end