Module: CouchbaseOrm

Defined in:
lib/rails/generators/couchbase_orm_generator.rb,
lib/couchbase-orm.rb,
lib/couchbase-orm/base.rb,
lib/couchbase-orm/n1ql.rb,
lib/couchbase-orm/error.rb,
lib/couchbase-orm/utils.rb,
lib/couchbase-orm/views.rb,
lib/couchbase-orm/encrypt.rb,
lib/couchbase-orm/version.rb,
lib/couchbase-orm/relation.rb,
lib/couchbase-orm/changeable.rb,
lib/couchbase-orm/connection.rb,
lib/couchbase-orm/timestamps.rb,
lib/couchbase-orm/types/date.rb,
lib/couchbase-orm/inspectable.rb,
lib/couchbase-orm/json_schema.rb,
lib/couchbase-orm/persistence.rb,
lib/couchbase-orm/types/array.rb,
lib/couchbase-orm/associations.rb,
lib/couchbase-orm/id_generator.rb,
lib/couchbase-orm/types/nested.rb,
lib/couchbase-orm/strict_loading.rb,
lib/couchbase-orm/utilities/enum.rb,
lib/couchbase-orm/utilities/join.rb,
lib/couchbase-orm/json_transcoder.rb,
lib/couchbase-orm/types/date_time.rb,
lib/couchbase-orm/types/encrypted.rb,
lib/couchbase-orm/types/timestamp.rb,
lib/couchbase-orm/utilities/index.rb,
lib/couchbase-orm/json_schema/loader.rb,
lib/couchbase-orm/proxies/n1ql_proxy.rb,
lib/couchbase-orm/timestamps/created.rb,
lib/couchbase-orm/timestamps/updated.rb,
lib/couchbase-orm/utilities/has_many.rb,
lib/couchbase-orm/active_record_compat.rb,
lib/couchbase-orm/proxies/bucket_proxy.rb,
lib/couchbase-orm/json_schema/validator.rb,
lib/couchbase-orm/proxies/results_proxy.rb,
lib/couchbase-orm/json_schema/validation.rb,
lib/couchbase-orm/utilities/query_helper.rb,
lib/couchbase-orm/utilities/ensure_unique.rb,
lib/couchbase-orm/proxies/collection_proxy.rb,
lib/couchbase-orm/utilities/ignored_properties.rb,
lib/couchbase-orm/json_schema/json_validation_error.rb,
lib/rails/generators/couchbase_orm/config/config_generator.rb,
lib/couchbase-orm/utilities/properties_always_exists_in_document.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ActiveRecordCompat, Associations, Changeable, Encrypt, EnsureUnique, Enum, Generators, HasMany, IgnoredProperties, Index, Inspectable, Join, JsonSchema, N1ql, Persistence, PropertiesAlwaysExistsInDocument, QueryHelper, Relation, StrictLoading, Timestamps, Types, Utils, Views Classes: Base, BucketProxy, CollectionProxy, Connection, Document, Error, IdGenerator, JsonTranscoder, N1qlProxy, NestedDocument, ResultsProxy, StrictLoadingViolationError

Constant Summary collapse

VERSION =
'2.0.5'

Class Method Summary collapse

Class Method Details

.loggerObject



20
21
22
# File 'lib/couchbase-orm.rb', line 20

def self.logger
    @@logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT).tap { |l| l.level = Logger::INFO unless ENV["COUCHBASE_ORM_DEBUG"] }
end

.logger=(logger) ⇒ Object



24
25
26
# File 'lib/couchbase-orm.rb', line 24

def self.logger=(logger)
    @@logger = logger
end

.try_load(id) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/couchbase-orm.rb', line 28

def self.try_load(id)
    result = nil
    was_array = id.is_a?(Array)
    if was_array && id.length == 1
        query_id = id.first
    else
        query_id = id
    end

    result = query_id.is_a?(Array) ? CouchbaseOrm::Base.bucket.default_collection.get_multi(query_id) : CouchbaseOrm::Base.bucket.default_collection.get(query_id)

    result = Array.wrap(result) if was_array

    if result&.is_a?(Array)
        return result.zip(id).map { |r, id| try_load_create_model(r, id) }.compact
    end

    return try_load_create_model(result, id)
end