Sha256: 33127b37a58b02dd5b10d743e207c3872b43725d644da07e5bc77bca7b1b69ce

Contents?: true

Size: 889 Bytes

Versions: 1

Compression:

Stored size: 889 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)
        super()

        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
        end
      end

      private

      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-2.1.0 lib/recite_csv/reader/builder.rb