Class: Dataset::Load

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(datasets, parent_binding) ⇒ Load

Returns a new instance of Load.



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

def initialize(datasets, parent_binding)
  @datasets = datasets
  @dataset_binding = SessionBinding.new(parent_binding)
  @helper_methods = Module.new
end

Instance Attribute Details

#dataset_bindingObject (readonly)

Returns the value of attribute dataset_binding.



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

def dataset_binding
  @dataset_binding
end

#datasetsObject (readonly)

Returns the value of attribute datasets.



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

def datasets
  @datasets
end

#helper_methodsObject (readonly)

Returns the value of attribute helper_methods.



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

def helper_methods
  @helper_methods
end

Instance Method Details

#execute(loaded_datasets, dataset_resolver) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dataset/load.rb', line 11

def execute(loaded_datasets, dataset_resolver)
  (datasets - loaded_datasets).each do |dataset|
    instance = dataset.new
    instance.extend dataset_binding.record_methods
    instance.extend dataset_binding.model_finders
    used_datasets(dataset, dataset_resolver).each do |ds|
      next unless ds.helper_methods
      instance.extend ds.helper_methods
      helper_methods.module_eval do
        include ds.helper_methods
      end
    end
    instance.load
  end
end

#used_datasets(dataset, dataset_resolver, collector = []) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/dataset/load.rb', line 27

def used_datasets(dataset, dataset_resolver, collector = [])
  dataset.used_datasets.each do |used|
    ds = dataset_resolver.resolve(used)
    used_datasets(ds, dataset_resolver, collector)
    collector << ds
  end if dataset.used_datasets
  collector << dataset
  collector.uniq
end