Sha256: 5e1daa277bf3007bcef4ca6e036aaf0018da86e6ffe4b2e2df6db0974535a0cc

Contents?: true

Size: 1.02 KB

Versions: 9

Compression:

Stored size: 1.02 KB

Contents

require_relative "generic"

module Railjet
  module Repository
    class ActiveRecord < Generic
      self.type = :record

      module RepositoryMethods
        def all
          record.all
        end

        def find_by_ids(ids)
          record.where(id: ids)
        end

        def build(args = {}, &block)
          record.new(args, &block)
        end

        def duplicate(object, args = {})
          object.dup.tap do |new_object|
            new_object.assign_attributes(args) if args.present?
            yield(new_object)                  if block_given?
          end
        end

        def persist(object)
          object.save!
        end

        def destroy(object)
          object.destroy!
        end

        def transaction(&block)
          record.transaction(&block)
        end

        private

        def query_columns
          columns = (record.column_names - [:created_at, :updated_at])
          columns.map { |column_name| "#{record.table_name}.#{column_name}" }
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
railjet-3.0.0 lib/railjet/repository/active_record.rb
railjet-2.1.1 lib/railjet/repository/active_record.rb
railjet-2.1 lib/railjet/repository/active_record.rb
railjet-2.0 lib/railjet/repository/active_record.rb
railjet-2.0.pre4 lib/railjet/repository/active_record.rb
railjet-2.0.pre3 lib/railjet/repository/active_record.rb
railjet-2.0.pre2 lib/railjet/repository/active_record.rb
railjet-2.0.pre1 lib/railjet/repository/active_record.rb
railjet-2.0.pre lib/railjet/repository/active_record.rb