Sha256: 944022ed581707386a25b5a5fd673a5b937516136464a5b678f36914a6173e2f

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

module CsvRowModel
  module Model
    module Base
      extend ActiveSupport::Concern

      included do
        # @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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
csv_row_model-0.4.1 lib/csv_row_model/model/base.rb
csv_row_model-0.4.0 lib/csv_row_model/model/base.rb