Sha256: 5dcc96904cc0fe8a6c6abfdfb67df5c17db1cda093fc33f897f3c7687465f80b

Contents?: true

Size: 560 Bytes

Versions: 2

Compression:

Stored size: 560 Bytes

Contents

# frozen_string_literal: true

module ActiveRecord
  class Relation
    def update_store(store_name)
      raise ArgumentError, "Empty store name to update" if store_name.blank?
      type = type_for_attribute(store_name.to_s).type
      raise TypeConflictError, store_type_error_msg(type) if %i(hstore jsonb).exclude?(type)
      klass = "ActiveRecord::Store::Flexible#{type.capitalize}".constantize
      klass.new(self, store_name)
    end

    private

    def store_type_error_msg(type)
      "Column type is not a known store: #{type}"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pgrel-0.3.0 lib/pgrel/active_record/relation.rb
pgrel-0.2.0 lib/pgrel/active_record/relation.rb