Class: ActiveRecordDataLoader::Dsl::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_data_loader/dsl/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass:, configuration:) ⇒ Model

Returns a new instance of Model.



9
10
11
12
13
14
15
16
17
18
# File 'lib/active_record_data_loader/dsl/model.rb', line 9

def initialize(klass:, configuration:)
  @klass = klass
  @columns = {}
  @row_count = configuration.default_row_count
  @batch_size = configuration.default_batch_size
  @raise_on_duplicates_flag = configuration.raise_on_duplicates
  @max_duplicate_retries = configuration.max_duplicate_retries
  @polymorphic_associations = []
  @belongs_to_associations = []
end

Instance Attribute Details

#belongs_to_associationsObject (readonly)

Returns the value of attribute belongs_to_associations.



6
7
8
# File 'lib/active_record_data_loader/dsl/model.rb', line 6

def belongs_to_associations
  @belongs_to_associations
end

#columnsObject (readonly)

Returns the value of attribute columns.



6
7
8
# File 'lib/active_record_data_loader/dsl/model.rb', line 6

def columns
  @columns
end

#klassObject (readonly)

Returns the value of attribute klass.



6
7
8
# File 'lib/active_record_data_loader/dsl/model.rb', line 6

def klass
  @klass
end

#polymorphic_associationsObject (readonly)

Returns the value of attribute polymorphic_associations.



6
7
8
# File 'lib/active_record_data_loader/dsl/model.rb', line 6

def polymorphic_associations
  @polymorphic_associations
end

#raise_on_duplicates_flagObject (readonly)

Returns the value of attribute raise_on_duplicates_flag.



6
7
8
# File 'lib/active_record_data_loader/dsl/model.rb', line 6

def raise_on_duplicates_flag
  @raise_on_duplicates_flag
end

#row_countObject (readonly)

Returns the value of attribute row_count.



6
7
8
# File 'lib/active_record_data_loader/dsl/model.rb', line 6

def row_count
  @row_count
end

Instance Method Details

#batch_size(size = nil) ⇒ Object



24
25
26
# File 'lib/active_record_data_loader/dsl/model.rb', line 24

def batch_size(size = nil)
  @batch_size = (size || @batch_size)
end

#belongs_to(assoc_name, eligible_set: nil) ⇒ Object



52
53
54
# File 'lib/active_record_data_loader/dsl/model.rb', line 52

def belongs_to(assoc_name, eligible_set: nil)
  @belongs_to_associations << BelongsToAssociation.new(@klass, assoc_name, eligible_set)
end

#column(name, func) ⇒ Object



42
43
44
# File 'lib/active_record_data_loader/dsl/model.rb', line 42

def column(name, func)
  @columns[name.to_sym] = func
end

#count(count) ⇒ Object



20
21
22
# File 'lib/active_record_data_loader/dsl/model.rb', line 20

def count(count)
  @row_count = count
end

#do_not_raise_on_duplicatesObject



32
33
34
# File 'lib/active_record_data_loader/dsl/model.rb', line 32

def do_not_raise_on_duplicates
  @raise_on_duplicates_flag = false
end

#max_duplicate_retries(retries = nil) ⇒ Object



36
37
38
39
40
# File 'lib/active_record_data_loader/dsl/model.rb', line 36

def max_duplicate_retries(retries = nil)
  return @max_duplicate_retries if retries.nil?

  @max_duplicate_retries = retries
end

#polymorphic(assoc_name, &block) ⇒ Object



46
47
48
49
50
# File 'lib/active_record_data_loader/dsl/model.rb', line 46

def polymorphic(assoc_name, &block)
  @polymorphic_associations << PolymorphicAssociation.new(
    @klass, assoc_name
  ).tap { |a| block.call(a) }
end

#raise_on_duplicatesObject



28
29
30
# File 'lib/active_record_data_loader/dsl/model.rb', line 28

def raise_on_duplicates
  @raise_on_duplicates_flag = true
end