Sha256: 58c3c9966a2865cc03dc33693618e84c5786df867e65fbf6e01e8a2868c91245

Contents?: true

Size: 727 Bytes

Versions: 4

Compression:

Stored size: 727 Bytes

Contents

module JupyterOnRails
  module Daru
    module DataFrameExt
      def write_model(model)
        if ActiveRecord.version >= Gem::Version.new('6.0.0.beta1')
          write_model_rails(model)
        else
          write_model_activerecord_import(model)
        end
      end

      private

      def write_model_activerecord_import(model)
        begin
          require 'activerecord-import'
        rescue LoadError
          raise 'write_model requires either Rails >= 6 or the activerecord-import gem'
        end

        records = map_rows(&:to_h).map(&model.method(:new))
        model.import(records)
      end

      def write_model_rails(model)
        model.insert_all(map_rows(&:to_h))
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jupyter_on_rails-0.6.0 lib/jupyter_on_rails/daru/data_frame_ext.rb
jupyter_on_rails-0.5.6 lib/jupyter_on_rails/daru/data_frame_ext.rb
jupyter_on_rails-0.5.5 lib/jupyter_on_rails/daru/data_frame_ext.rb
jupyter_on_rails-0.5.4 lib/jupyter_on_rails/daru/data_frame_ext.rb