Sha256: 8c27faad0952f27b45d078527869438d6eada12ffe2790aa6dca7e7b42f64d44

Contents?: true

Size: 1.02 KB

Versions: 6

Compression:

Stored size: 1.02 KB

Contents

module Granite
  module Form
    module Model
      module Associations
        module PersistenceAdapters
          class ActiveRecord < Base
            class ReferencedProxy < Granite::Form::Model::Associations::Collection::Proxy
              # You can't create data directly through ActiveRecord::Relation
              METHODS_EXCLUDED_FROM_DELEGATION = %w[build create create!].map(&:to_sym).freeze

              attr_reader :association
              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
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
granite-form-0.5.0 lib/granite/form/model/associations/persistence_adapters/active_record/referenced_proxy.rb
granite-form-0.4.0 lib/granite/form/model/associations/persistence_adapters/active_record/referenced_proxy.rb
granite-form-0.3.0 lib/granite/form/model/associations/persistence_adapters/active_record/referenced_proxy.rb
granite-form-0.2.0 lib/granite/form/model/associations/persistence_adapters/active_record/referenced_proxy.rb
granite-form-0.1.1 lib/granite/form/model/associations/persistence_adapters/active_record/referenced_proxy.rb
granite-form-0.1.0 lib/granite/form/model/associations/persistence_adapters/active_record/referenced_proxy.rb