Sha256: 2f0bef894581c18415fd34d50600a41e1ba9b42cf3e8e79a3eb8cc38722cfe57

Contents?: true

Size: 734 Bytes

Versions: 1

Compression:

Stored size: 734 Bytes

Contents

module ActiveData
  module Model
    module Associations
      module Collection
        class Referenced < Proxy
          METHODS_EXCLUDED_FROM_DELEGATION = %w[build create create!].map(&:to_sym).freeze
          delegate :scope, to: :@association

          def method_missing(method, *args, &block)
            delegate_to_scope?(method) ? scope.send(method, *args, &block) : super
          end

          def respond_to_missing?(method, include_private = false)
            delegate_to_scope?(method) || super
          end

        private

          def delegate_to_scope?(method)
            METHODS_EXCLUDED_FROM_DELEGATION.exclude?(method) && scope.respond_to?(method)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_data-1.0.0 lib/active_data/model/associations/collection/referenced.rb