Sha256: 9e561d24e1c904f56fa710f134eaf8cab4656b67c2a5e045ac28d94450aed70a

Contents?: true

Size: 1.68 KB

Versions: 3

Compression:

Stored size: 1.68 KB

Contents

module Granite
  module Form
    module Model
      module Associations
        module PersistenceAdapters
          class Base
            attr_reader :data_source, :primary_key, :scope_proc

            def initialize(data_source, primary_key, scope_proc = nil)
              @data_source = data_source
              @primary_key = primary_key
              @scope_proc = scope_proc
            end

            def build(_attributes)
              raise NotImplementedError, 'Should be implemented in inhereted adapter. Build new instance of data object by attributes'
            end

            def scope(_owner, _source)
              raise NotImplementedError, 'Should be implemented in inhereted adapter. Better to be Enumerable'
            end

            def find_one(owner, identificator)
              scope(owner, identificator).first
            end

            def find_all(owner, identificators)
              scope(owner, identificators).to_a
            end

            def identify(_object)
              raise NotImplementedError, 'Should be implemented in inhereted adapter. Field to be used as primary_key for object'
            end

            def data_type
              raise NotImplementedError, 'Should be implemented in inhereted adapter. Type of data object for type_check'
            end

            def primary_key_type
              raise NotImplementedError, 'Should be implemented in inhereted adapter. Ruby data type'
            end

            def referenced_proxy
              raise NotImplementedError, 'Should be implemented in inhereted adapter. Object to manage proxying of methods to scope.'
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
granite-form-0.5.0 lib/granite/form/model/associations/persistence_adapters/base.rb
granite-form-0.4.0 lib/granite/form/model/associations/persistence_adapters/base.rb
granite-form-0.3.0 lib/granite/form/model/associations/persistence_adapters/base.rb