Sha256: 4be96e610b9e435652b976873d1b1e3e7305ce5b83d435a04819086e32e09948

Contents?: true

Size: 782 Bytes

Versions: 1

Compression:

Stored size: 782 Bytes

Contents

module ROM
  module EnvironmentPlugins
    # Automatically registers relations, mappers and commands as they are defined
    #
    # For now this plugin is always enabled
    #
    # @api public
    module AutoRegistration
      # @api private
      def self.apply(environment, options = {})
        if_proc = options.fetch(:if, ->(*args) { true })

        ROM::Relation.on(:inherited) do |relation|
          environment.register_relation(relation) if if_proc.call(relation)
        end

        ROM::Command.on(:inherited) do |command|
          environment.register_command(command) if if_proc.call(command)
        end

        ROM::Mapper.on(:inherited) do |mapper|
          environment.register_mapper(mapper) if if_proc.call(mapper)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-0.9.0 lib/rom/environment_plugins/auto_registration.rb