Module: EntityStore::Build

Defined in:
lib/entity_store/entity_store.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.assure(instance) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/entity_store/entity_store.rb', line 63

def self.assure(instance)
  if instance.category.nil?
    raise Error, "Category is not declared"
  end

  if instance.entity_class.nil?
    raise Error, "Entity is not declared"
  end

  if instance.projection_class.nil?
    raise Error, "Projection is not declared"
  end

  if instance.reader_class.nil?
    raise Error, "Reader is not declared"
  end

  snapshot_class = instance.snapshot_class
  unless snapshot_class.nil?
    if snapshot_class.respond_to?(:assure)
      snapshot_class.assure(instance)
    end
  end
end

Instance Method Details

#build(snapshot_interval: nil, session: nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/entity_store/entity_store.rb', line 44

def build(snapshot_interval: nil, session: nil)
  instance = new

  Build.assure(instance)

  instance.session = session

  EntityCache.configure(
    instance,
    entity_class,
    persist_interval: instance.snapshot_interval,
    external_store: instance.snapshot_class,
    external_store_session: session,
    attr_name: :cache
  )

  instance
end