Module: CouchbaseOrm
- Defined in:
- lib/couchbase-orm.rb,
lib/couchbase-orm/base.rb,
lib/couchbase-orm/n1ql.rb,
lib/couchbase-orm/error.rb,
lib/couchbase-orm/views.rb,
lib/couchbase-orm/encrypt.rb,
lib/couchbase-orm/version.rb,
lib/couchbase-orm/relation.rb,
lib/couchbase-orm/types/raw.rb,
lib/couchbase-orm/connection.rb,
lib/couchbase-orm/types/date.rb,
lib/couchbase-orm/types/hash.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/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/extensions/string.rb,
lib/couchbase-orm/attributes/dynamic.rb,
lib/couchbase-orm/proxies/n1ql_proxy.rb,
lib/couchbase-orm/utilities/embedded.rb,
lib/couchbase-orm/utilities/has_many.rb,
lib/couchbase-orm/proxies/bucket_proxy.rb,
lib/couchbase-orm/utilities/embeds_one.rb,
lib/couchbase-orm/proxies/results_proxy.rb,
lib/couchbase-orm/utilities/embeds_many.rb,
lib/couchbase-orm/utilities/query_helper.rb,
lib/couchbase-orm/utilities/ensure_unique.rb,
lib/couchbase-orm/proxies/collection_proxy.rb,
lib/rails/generators/couchbase_orm_generator.rb,
lib/couchbase-orm/utilities/ignored_properties.rb,
lib/couchbase-orm/utilities/validates_embedded.rb,
lib/couchbase-orm/validators/polymorphic_type_validator.rb,
lib/couchbase-orm/validators/embedded_associated_validator.rb,
lib/rails/generators/couchbase_orm/config/config_generator.rb
Overview
:nodoc:
Defined Under Namespace
Modules: ActiveRecordCompat, Associations, AttributesDynamic, Embedded, EmbedsMany, EmbedsOne, Encrypt, EnsureUnique, Enum, Extensions, Generators, HasMany, IgnoredProperties, Index, Join, N1ql, Persistence, QueryHelper, Relation, Types, ValidatesEmbedded, Views Classes: Base, BucketProxy, CollectionProxy, Connection, Document, EmbeddedAssociatedValidator, Error, IdGenerator, JsonTranscoder, N1qlProxy, NestedDocument, PolymorphicTypeValidator, ResultsProxy
Constant Summary collapse
- VERSION =
'1.6.4'
Class Method Summary collapse
-
.logger ⇒ Logger
if COUCHBASE_ORM_DEBUG environement variable exist then logger is set to Logger::DEBUG level else logger is set to Logger::INFO level.
-
.logger=(logger) ⇒ Logger
Allows you to set a logger for CouchbaseOrm, which can be usueful for logging messages or errors related to CouchbaseOrm.
-
.try_load(id) ⇒ Object+
Attempts to load a record or records from the Couchbase database.
-
.try_load_create_model(result, id) ⇒ Object?
Creates a model from the fetched data and ID.
Class Method Details
.logger ⇒ Logger
if COUCHBASE_ORM_DEBUG environement variable exist then logger is set to Logger::DEBUG level else logger is set to Logger::INFO level
30 31 32 33 34 |
# File 'lib/couchbase-orm.rb', line 30 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) ⇒ Logger
Allows you to set a logger for CouchbaseOrm, which can be usueful for logging messages or errors related to CouchbaseOrm
47 48 49 |
# File 'lib/couchbase-orm.rb', line 47 def self.logger=(logger) @@logger = logger end |
.try_load(id) ⇒ Object+
Attempts to load a record or records from the Couchbase database.
This method can handle both single IDs and arrays of IDs. It adapts its behavior based on the type and quantity of the input.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/couchbase-orm.rb', line 58 def self.try_load(id) result = nil was_array = id.is_a?(Array) query_id = if was_array && id.length == 1 id.first else 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 try_load_create_model(result, id) end |
.try_load_create_model(result, id) ⇒ Object?
Creates a model from the fetched data and ID.
This method checks the type of the fetched document and matches it against the design documents of known models. If a match is found, it creates and returns an instance of the corresponding model.
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/couchbase-orm.rb', line 86 def self.try_load_create_model(result, id) ddoc = result&.content&.[]('type') return nil unless ddoc ::CouchbaseOrm::Base.descendants.each do |model| if model.design_document == ddoc return model.instantiate(result.content, id, nil, model) end end nil end |