Sha256: efdb6215e15f14bec0f2883ddeb5108a2e160bba56592b24faf3e6bf2cb8a36d

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

module ActiveRecord
  # client side ActiveRecord::Base proxy
  class Base
    include InstanceMethods
    extend  ClassMethods

    scope :limit, ->() {}
    scope :offset, ->() {}

    finder_method :__hyperstack_internal_scoped_last
    scope :__hyperstack_internal_scoped_last_n, ->(n) { last(n) }

    def self.where(*args)
      if args[0].is_a? Hash
        # we can compute membership in the scope when the arg is a hash
        __hyperstack_internal_where_hash_scope(args[0])
      else
        # otherwise the scope has to always be computed on the server
        __hyperstack_internal_where_sql_scope(*args)
      end
    end

    scope :__hyperstack_internal_where_hash_scope,
          client: ->(attrs) { !attrs.detect { |k, v| self[k] != v } }

    scope :__hyperstack_internal_where_sql_scope

    ReactiveRecord::ScopeDescription.new(
      self, :___hyperstack_internal_scoped_find_by,
      client: ->(attrs) { !attrs.detect { |attr, value| attributes[attr] != value } }
    )

    def self.__hyperstack_internal_scoped_find_by(attrs)
      collection = all.apply_scope(:___hyperstack_internal_scoped_find_by, attrs).observed
      if !collection.collection
        collection._find_by_initializer(self, attrs)
      else
        collection.first
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hyper-model-1.0.alpha1.8 lib/reactive_record/active_record/base.rb
hyper-model-1.0.alpha1.7 lib/reactive_record/active_record/base.rb