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/has_many.rb,
lib/couchbase-orm/proxies/bucket_proxy.rb,
lib/couchbase-orm/proxies/results_proxy.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/rails/generators/couchbase_orm/config/config_generator.rb
Overview
:nodoc:
Defined Under Namespace
Modules: ActiveRecordCompat, Associations, AttributesDynamic, Encrypt, EnsureUnique, Enum, Extensions, Generators, HasMany, IgnoredProperties, Index, Join, N1ql, Persistence, QueryHelper, Relation, Types, Views Classes: Base, BucketProxy, CollectionProxy, Connection, Document, Error, IdGenerator, JsonTranscoder, N1qlProxy, NestedDocument, ResultsProxy
Constant Summary collapse
- VERSION =
'1.3.0'
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
26 27 28 29 30 |
# File 'lib/couchbase-orm.rb', line 26 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
43 44 45 |
# File 'lib/couchbase-orm.rb', line 43 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.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/couchbase-orm.rb', line 54 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.
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/couchbase-orm.rb', line 82 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.new(result, id: id) end end nil end |