Sha256: 589d850674fedd394de95035ea07aa5a39e6c77e274889c6b4dd501fab8cfce8

Contents?: true

Size: 1.74 KB

Versions: 11

Compression:

Stored size: 1.74 KB

Contents

require 'csv_row_model/model/csv_string_model'

require 'csv_row_model/model/columns'
require 'csv_row_model/model/children'
require 'csv_row_model/model/dynamic_columns'

module CsvRowModel
  # Base module for representing a RowModel---a model that represents row(s).
  module Model
    extend ActiveSupport::Concern

    included do
      include Concerns::InheritedClassVar

      include ActiveWarnings
      include Validators::ValidateAttributes

      include Columns
      include Children
      include DynamicColumns

      # @return [Model] return the parent, if this instance is a child
      attr_reader :parent

      # @return [DateTime] return when self has been intialized
      attr_reader :initialized_at

      validate_attributes :parent
    end

    # @param [NilClass] source not used here, see {Input}
    # @param [Hash] options
    # @option options [String] :parent if the instance is a child, pass the parent
    def initialize(source=nil, options={})
      @initialized_at = DateTime.now
      @parent = options[:parent]
    end

    # Safe to override.
    #
    # @return [Boolean] returns true, if this instance should be skipped
    def skip?
      !valid?
    end

    # Safe to override.
    #
    # @return [Boolean] returns true, if the entire csv file should stop reading
    def abort?
      false
    end

    class_methods do
      # @return [Class] the Class with validations of the csv_string_model
      def csv_string_model_class
        @csv_string_model_class ||= inherited_custom_class(:csv_string_model_class, CsvStringModel)
      end

      protected
      # Called to add validations to the csv_string_model_class
      def csv_string_model(&block)
        csv_string_model_class.class_eval(&block)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
csv_row_model-0.3.10 lib/csv_row_model/model.rb
csv_row_model-0.3.9 lib/csv_row_model/model.rb
csv_row_model-0.3.8 lib/csv_row_model/model.rb
csv_row_model-0.3.7 lib/csv_row_model/model.rb
csv_row_model-0.3.6 lib/csv_row_model/model.rb
csv_row_model-0.3.5 lib/csv_row_model/model.rb
csv_row_model-0.3.4 lib/csv_row_model/model.rb
csv_row_model-0.3.3 lib/csv_row_model/model.rb
csv_row_model-0.3.2 lib/csv_row_model/model.rb
csv_row_model-0.3.1 lib/csv_row_model/model.rb
csv_row_model-0.3.0 lib/csv_row_model/model.rb