Module: EntityStore::Controls::EntityStore

Defined in:
lib/entity_store/controls/entity_store.rb

Defined Under Namespace

Modules: Category

Constant Summary collapse

Example =
self.example_class

Class Method Summary collapse

Class Method Details

.example(category: nil, entity_class: nil, projection_class: nil, reader_class: nil, snapshot_class: nil, snapshot_interval: nil, snapshot_interval_keyword: nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/entity_store/controls/entity_store.rb', line 4

def self.example(category: nil, entity_class: nil, projection_class: nil, reader_class: nil, snapshot_class: nil, snapshot_interval: nil, snapshot_interval_keyword: nil)
  if category.nil? && entity_class.nil? && projection_class.nil? && reader_class.nil? && snapshot_class.nil? && snapshot_interval.nil?  && snapshot_interval_keyword.nil?
    store_class = Example
  else
    store_class = example_class(category: category, entity_class: entity_class, projection_class: projection_class, reader_class: reader_class, snapshot_class: snapshot_class, snapshot_interval: snapshot_interval, snapshot_interval_keyword: snapshot_interval_keyword)
  end

  instance = store_class.build
  instance
end

.example_class(category: nil, entity_class: nil, projection_class: nil, reader_class: nil, snapshot_class: nil, snapshot_interval: nil, snapshot_interval_keyword: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/entity_store/controls/entity_store.rb', line 15

def self.example_class(category: nil, entity_class: nil, projection_class: nil, reader_class: nil, snapshot_class: nil, snapshot_interval: nil, snapshot_interval_keyword: nil)
  if category == :none
    category = nil
  else
    category ||= Controls::Category.example
  end

  if entity_class == :none
    entity_class = nil
  else
    entity_class ||= Controls::Entity::Example
  end

  if projection_class == :none
    projection_class = nil
  else
    projection_class ||= Controls::Projection::Example
  end

  if reader_class == :none
    reader_class = nil
  else
    reader_class ||= Controls::Reader::Example
  end

  Class.new do
    include ::EntityStore

    category category
    entity entity_class
    projection projection_class
    reader reader_class

    unless snapshot_class.nil?
      if snapshot_interval_keyword.nil?
        snapshot snapshot_class, snapshot_interval
      else
        snapshot snapshot_class, interval: snapshot_interval_keyword
      end
    end
  end
end