Module: CouchbaseOrm::AttributesDynamic
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/couchbase-orm/attributes/dynamic.rb
Instance Method Summary collapse
-
#respond_to?(name, include_private = false) ⇒ true | false
Override respond_to? so it responds properly for dynamic attributes.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Used for allowing accessor methods for dynamic attributes.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/couchbase-orm/attributes/dynamic.rb', line 121 def method_missing(name, *args) attr = name.to_s return super unless attr.reader != 'id' && attributes.key?(attr.reader) getter = attr.reader if attr.writer? define_dynamic_writer(getter) @attributes.write_from_user(getter, args.first) args.first else value = @attributes[getter].value type = lookup_attribute_type(value) @attributes[getter] = ActiveModel::Attribute.from_database(getter, value, type) define_dynamic_reader(getter) send(getter) end end |
Instance Method Details
#respond_to?(name, include_private = false) ⇒ true | false
Override respond_to? so it responds properly for dynamic attributes.
17 18 19 |
# File 'lib/couchbase-orm/attributes/dynamic.rb', line 17 def respond_to?(name, include_private = false) super || @attributes.key?(name.to_s.reader) end |