Sha256: c52eaa4a49853ce99fb589f50cae754505965212943778cbc807a864bbcb7545

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

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
      # Say "yes" for envs that have this plugin enabled
      #
      # By default it says "no" in Environment#auto_registration?
      #
      # @api private
      def auto_registration?
        true
      end

      # @api private
      def self.apply(environment, options = {})
        environment.extend(AutoRegistration)

        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.1 lib/rom/environment_plugins/auto_registration.rb