Class: ActiveRecordDataLoader::Dsl::Model
- Inherits:
-
Object
- Object
- ActiveRecordDataLoader::Dsl::Model
- Defined in:
- lib/active_record_data_loader/dsl/model.rb
Instance Attribute Summary collapse
-
#belongs_to_associations ⇒ Object
readonly
Returns the value of attribute belongs_to_associations.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#polymorphic_associations ⇒ Object
readonly
Returns the value of attribute polymorphic_associations.
-
#raise_on_duplicates_flag ⇒ Object
readonly
Returns the value of attribute raise_on_duplicates_flag.
-
#row_count ⇒ Object
readonly
Returns the value of attribute row_count.
Instance Method Summary collapse
- #batch_size(size = nil) ⇒ Object
- #belongs_to(assoc_name, eligible_set: nil) ⇒ Object
- #column(name, func) ⇒ Object
- #count(count) ⇒ Object
- #do_not_raise_on_duplicates ⇒ Object
-
#initialize(klass:, configuration:) ⇒ Model
constructor
A new instance of Model.
- #max_duplicate_retries(retries = nil) ⇒ Object
- #polymorphic(assoc_name, &block) ⇒ Object
- #raise_on_duplicates ⇒ Object
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_associations ⇒ Object (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 |
#columns ⇒ Object (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 |
#klass ⇒ Object (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_associations ⇒ Object (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_flag ⇒ Object (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_count ⇒ Object (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_duplicates ⇒ Object
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_duplicates ⇒ Object
28 29 30 |
# File 'lib/active_record_data_loader/dsl/model.rb', line 28 def raise_on_duplicates @raise_on_duplicates_flag = true end |