Sha256: 3b22fab1289ef6d9dfe825710cda4de1a447379e6bdcb0c0b3e51da87482d75d

Contents?: true

Size: 870 Bytes

Versions: 2

Compression:

Stored size: 870 Bytes

Contents

module CSVImporter
  # The configuration of a CSVImporter
  class Config
    include Virtus.model

    attribute :model
    attribute :column_definitions, Array[ColumnDefinition], default: proc { [] }
    attribute :identifiers, Array[Symbol], default: []
    attribute :when_invalid, Symbol, default: proc { :skip }
    attribute :after_build_blocks, Array[Proc], default: []
    attribute :after_save_blocks, Array[Proc], default: []

    def initialize_copy(orig)
      super
      self.column_definitions = orig.column_definitions.dup
      self.identifiers = orig.identifiers.dup
      self.after_save_blocks = orig.after_save_blocks.dup
      self.after_build_blocks = orig.after_build_blocks.dup
    end

    def after_build(block)
      self.after_build_blocks << block
    end

    def after_save(block)
      self.after_save_blocks << block
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
csv-importer-0.4.0 lib/csv_importer/config.rb
csv-importer-0.3.2 lib/csv_importer/config.rb