Sha256: f9237decc6cb60cf4f9a049e17e8d92ff30bf35d70636fbea049a8d844a82cf3

Contents?: true

Size: 830 Bytes

Versions: 1

Compression:

Stored size: 830 Bytes

Contents

# frozen_string_literal: true

require "recite_csv/header"
require "recite_csv/row"
require "recite_csv/reader/core"
require "recite_csv/reader/dsl"

module ReciteCSV
  module Reader
    class Builder < ::Module
      def initialize(header_definition, &block)
        definition = Header::Definition.dispatch(header_definition)
        @definition = definition
        @row_class = ::Class.new(Row::Base) do |klass|
          klass.include definition.build_column_methods_module
          klass.class_exec(&block) if block_given?
        end
      end

      def included(class_or_module)
        class_or_module.include Core
        class_or_module.const_set(:Row, @row_class)
        class_or_module.const_set(:DEFAULT_CSV_OPTIONS, @definition.default_csv_options)
        class_or_module.extend DSL
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
recite_csv-0.1.1 lib/recite_csv/reader/builder.rb