Module: CouchbaseOrm::ActiveRecordCompat
- Extended by:
- ActiveSupport::Concern
- Included in:
- Document
- Defined in:
- lib/couchbase-orm/active_record_compat.rb
Overview
Set of methods defined in ActiveRecord and needed for CouchbaseOrm try to avoid dependencies on too many active record classes by exemple we don’t want to go down to the concept of tables
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
- #has_attribute?(attr_name) ⇒ Boolean
- #slice(*methods) ⇒ Object
- #values_at(*methods) ⇒ Object
Instance Method Details
#_has_attribute?(attr_name) ⇒ Boolean
63 64 65 |
# File 'lib/couchbase-orm/active_record_compat.rb', line 63 def _has_attribute?(attr_name) attribute_names.include?(attr_name.to_s) end |
#_write_attribute(attr_name, value) ⇒ Object
86 87 88 89 |
# File 'lib/couchbase-orm/active_record_compat.rb', line 86 def _write_attribute(attr_name, value) @attributes.write_from_user(attr_name.to_s, value) value end |
#attribute_for_inspect(attr_name) ⇒ Object
67 68 69 70 |
# File 'lib/couchbase-orm/active_record_compat.rb', line 67 def attribute_for_inspect(attr_name) value = send(attr_name) value.inspect end |
#attribute_names ⇒ Object
73 74 75 |
# File 'lib/couchbase-orm/active_record_compat.rb', line 73 def attribute_names self.class.attribute_names end |
#attribute_present?(attribute) ⇒ Boolean
81 82 83 84 |
# File 'lib/couchbase-orm/active_record_compat.rb', line 81 def attribute_present?(attribute) value = send(attribute) !value.nil? && !(value.respond_to?(:empty?) && value.empty?) end |
#has_attribute?(attr_name) ⇒ Boolean
77 78 79 |
# File 'lib/couchbase-orm/active_record_compat.rb', line 77 def has_attribute?(attr_name) @attributes.key?(attr_name.to_s) end |
#slice(*methods) ⇒ Object
55 56 57 |
# File 'lib/couchbase-orm/active_record_compat.rb', line 55 def slice(*methods) HashWithIndifferentAccess.new(methods.flatten.to_h { |method| [method, public_send(method)] }) end |
#values_at(*methods) ⇒ Object
59 60 61 |
# File 'lib/couchbase-orm/active_record_compat.rb', line 59 def values_at(*methods) methods.flatten.map! { |method| public_send(method) } end |