Class: Dataset::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/dataset/session.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database, dataset_resolver = Resolver.default) ⇒ Session

Returns a new instance of Session.



5
6
7
8
9
10
# File 'lib/dataset/session.rb', line 5

def initialize(database, dataset_resolver = Resolver.default)
  @database = database
  @dataset_resolver = dataset_resolver
  @datasets = Hash.new
  @load_stack = []
end

Instance Attribute Details

#dataset_resolverObject

Returns the value of attribute dataset_resolver.



3
4
5
# File 'lib/dataset/session.rb', line 3

def dataset_resolver
  @dataset_resolver
end

Instance Method Details

#add_dataset(test_class, dataset_identifier) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/dataset/session.rb', line 12

def add_dataset(test_class, dataset_identifier)
  dataset = dataset_resolver.resolve(dataset_identifier)
  if dataset.used_datasets
    dataset.used_datasets.each { |used_dataset| self.add_dataset(test_class, used_dataset) }
  end
  datasets_for(test_class) << dataset
end

#datasets_for(test_class) ⇒ Object



20
21
22
23
24
# File 'lib/dataset/session.rb', line 20

def datasets_for(test_class)
  if test_class.superclass
    @datasets[test_class] ||= Collection.new(datasets_for(test_class.superclass) || [])
  end
end

#load_datasets_for(test_class) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dataset/session.rb', line 26

def load_datasets_for(test_class)
  datasets = datasets_for(test_class)
  if last_load = @load_stack.last
    if last_load.datasets == datasets
      current_load = Reload.new(last_load)
    elsif last_load.datasets.subset?(datasets)
      @database.capture(last_load.datasets)
      current_load = Load.new(datasets, last_load.dataset_binding)
      current_load.execute(last_load.datasets, @dataset_resolver)
      @load_stack.push(current_load)
    else
      @load_stack.pop
      last_load = @load_stack.last
      @database.restore(last_load.datasets) if last_load
      current_load = load_datasets_for(test_class)
    end
  else
    @database.clear
    current_load = Load.new(datasets, @database)
    current_load.execute([], @dataset_resolver)
    @load_stack.push(current_load)
  end
  current_load
end