class ROM::Changeset

Abstract Changeset class

If you inherit from this class you need to configure additional settings

@example define a custom changeset using :upsert command

class NewTag < ROM::Changeset[:tags]
  command_type :upsert
end

@abstract

Constants

VERSION

Public Class Methods

[](relation_name) click to toggle source

Create a changeset class preconfigured for a specific relation

@example

class NewUserChangeset < ROM::Changeset::Create[:users]
end

users.changeset(NewUserChangeset).data(name: 'Jane')

@api public

# File lib/rom/changeset.rb, line 108
def self.[](relation_name)
  fetch_or_store([relation_name, self]) {
    Class.new(self) { relation(relation_name) }
  }
end
use(plugin, **options) click to toggle source

Enable a plugin for the changeset

@api public

# File lib/rom/changeset.rb, line 117
def self.use(plugin, **options)
  ROM.plugin_registry[:changeset].fetch(plugin).apply_to(self, **options)
end

Public Instance Methods

command() click to toggle source

Return a command for this changeset

@return [ROM::Command]

@api private

# File lib/rom/changeset.rb, line 163
def command
  relation.command(command_type, **command_compiler_options)
end
command_compiler_options() click to toggle source

Return configured command compiler options

@return [Hash]

@api private

# File lib/rom/changeset.rb, line 172
def command_compiler_options
  command_options.merge(use: command_plugins.keys, plugins_options: command_plugins)
end
commit() click to toggle source

Persist changeset

@example

changeset = users.changeset(name: 'Jane')
changeset.commit
# => { id: 1, name: 'Jane' }

@return [Hash, Array]

@api public

# File lib/rom/changeset.rb, line 145
def commit
  command.call
end
inspect() click to toggle source

Return string representation of the changeset

@return [String]

@api public

# File lib/rom/changeset.rb, line 154
def inspect
  %(#<#{self.class} relation=#{relation.name.inspect}>)
end
new(relation, **new_options) click to toggle source

Return a new changeset with provided relation

New options can be provided too

@param [Relation] relation @param [Hash] new_options

@return [Changeset]

@api public

# File lib/rom/changeset.rb, line 131
def new(relation, **new_options)
  self.class.new(relation, **options, **new_options)
end