Sha256: 27d8a064295e343a324f5078b5a4d46c8cb0226ef39a5c2d13db8aeecc06d561
Contents?: true
Size: 1.75 KB
Versions: 1
Compression:
Stored size: 1.75 KB
Contents
# frozen_string_literal: true require "dry/core/class_attributes" require "rom/command" module ROM class Command extend Dry::Core::ClassAttributes module Restrictable extend ROM::Notifications::Listener subscribe("configuration.commands.class.before_build") do |event| command = event[:command] relation = event[:relation] command.extend_for_relation(relation) if command.restrictable end # @api private def create_class(relation: nil, **, &block) klass = super klass.extend_for_relation(relation) if relation && klass.restrictable klass end end class << self prepend Restrictable prepend SettingProxy def setting_mapping @setting_mapper ||= { adapter: [:component, :adapter], relation: [:component, %i[relation namespace]], register_as: [:component, :id], restrictable: [], result: [], input: [] }.freeze end end # Extend a command class with relation view methods # # @param [Relation] relation # # @return [Class] # # @api public # @deprecated def self.extend_for_relation(relation) include(relation_methods_mod(relation.class)) end # @api private def self.relation_methods_mod(relation_class) Module.new do relation_class.view_methods.each do |meth| module_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{meth}(*args) response = relation.public_send(:#{meth}, *args) if response.is_a?(relation.class) new(response) else response end end RUBY end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rom-6.0.0.alpha1 | lib/rom/compat/command.rb |