Module: CouchbaseOrm::ActiveRecordCompat
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #_has_attribute?(attr_name) ⇒ Boolean
- #_write_attribute(attr_name, value) ⇒ Object
- #attribute_for_inspect(attr_name) ⇒ Object
- #attribute_names ⇒ Object
- #attribute_present?(attribute) ⇒ Boolean
- #format_for_inspect(value) ⇒ Object
- #has_attribute?(attr_name) ⇒ Boolean
-
#primary_key_values_present? ⇒ Boolean
ActiveRecord 7.1 compatibility.
- #read_attribute(attr_name, &block) ⇒ Object
Instance Method Details
#_has_attribute?(attr_name) ⇒ Boolean
113 114 115 |
# File 'lib/couchbase-orm/base.rb', line 113 def _has_attribute?(attr_name) attribute_names.include?(attr_name.to_s) end |
#_write_attribute(attr_name, value) ⇒ Object
151 152 153 154 |
# File 'lib/couchbase-orm/base.rb', line 151 def _write_attribute(attr_name, value) @attributes.write_from_user(attr_name.to_s, value) value end |
#attribute_for_inspect(attr_name) ⇒ Object
122 123 124 125 |
# File 'lib/couchbase-orm/base.rb', line 122 def attribute_for_inspect(attr_name) value = send(attr_name) value.inspect end |
#attribute_names ⇒ Object
138 139 140 |
# File 'lib/couchbase-orm/base.rb', line 138 def attribute_names self.class.attribute_names end |
#attribute_present?(attribute) ⇒ Boolean
146 147 148 149 |
# File 'lib/couchbase-orm/base.rb', line 146 def attribute_present?(attribute) value = send(attribute) !value.nil? && !(value.respond_to?(:empty?) && value.empty?) end |
#format_for_inspect(value) ⇒ Object
128 129 130 131 132 133 134 135 136 |
# File 'lib/couchbase-orm/base.rb', line 128 def format_for_inspect(value) if value.is_a?(String) && value.length > 50 "#{value[0, 50]}...".inspect elsif value.is_a?(Date) || value.is_a?(Time) %("#{value.to_s(:db)}") else value.inspect end end |
#has_attribute?(attr_name) ⇒ Boolean
142 143 144 |
# File 'lib/couchbase-orm/base.rb', line 142 def has_attribute?(attr_name) @attributes.key?(attr_name.to_s) end |
#primary_key_values_present? ⇒ Boolean
ActiveRecord 7.1 compatibility
118 119 120 |
# File 'lib/couchbase-orm/base.rb', line 118 def primary_key_values_present? !id.nil? end |
#read_attribute(attr_name, &block) ⇒ Object
156 157 158 159 160 161 162 |
# File 'lib/couchbase-orm/base.rb', line 156 def read_attribute(attr_name, &block) name = attr_name.to_s name = self.class.attribute_aliases[name] || name name = @primary_key if name == 'id' && @primary_key @attributes.fetch_value(name, &block) end |