module HasMetadataColumn::Extensions
Public Instance Methods
_attribute(attr)
click to toggle source
Calls superclass method
# File lib/has_metadata_column.rb, line 266 def _attribute(attr) return super unless self.class.metadata_column_fields.include?(attr.to_sym) attribute attr end
attribute(attr)
click to toggle source
ATTRIBUTE MATCHER METHODS
Calls superclass method
# File lib/has_metadata_column.rb, line 251 def attribute(attr) return super unless self.class.metadata_column_fields.include?(attr.to_sym) options = self.class.metadata_column_fields[attr.to_sym] || {} default = options.include?(:default) ? options[:default] : nil _metadata_hash.include?(attr) ? HasMetadataColumn.metadata_typecast(_metadata_hash[attr], options[:type]) : default end
attribute=(attr, value)
click to toggle source
Calls superclass method
# File lib/has_metadata_column.rb, line 271 def attribute=(attr, value) return super unless self.class.metadata_column_fields.include?(attr.to_sym) attribute_will_change! attr old = _metadata_hash[attr.to_s] send :"#{self.class.metadata_column}=", _metadata_hash.merge(attr.to_s => value).to_json @_metadata_hash = nil value end
attribute_before_type_cast(attr)
click to toggle source
Calls superclass method
# File lib/has_metadata_column.rb, line 259 def attribute_before_type_cast(attr) return super unless self.class.metadata_column_fields.include?(attr.to_sym) options = self.class.metadata_column_fields[attr.to_sym] || {} default = options.include?(:default) ? options[:default] : nil _metadata_hash.include?(attr) ? _metadata_hash[attr] : default end
attribute_method?(attr)
click to toggle source
Calls superclass method
# File lib/has_metadata_column.rb, line 290 def attribute_method?(attr) self.class.metadata_column_fields.include?(attr.to_sym) || super end
attribute_will_change!(attr)
click to toggle source
Calls superclass method
# File lib/has_metadata_column.rb, line 242 def attribute_will_change!(attr) unless attribute_names.include?(attr) send :"#{self.class.metadata_column}_will_change!" end super end
keys_for_partial_write()
click to toggle source
Calls superclass method
# File lib/has_metadata_column.rb, line 294 def keys_for_partial_write super - self.class.metadata_column_fields.keys.map(&:to_s) end
query_attribute(attr)
click to toggle source
Calls superclass method
# File lib/has_metadata_column.rb, line 281 def query_attribute(attr) return super unless self.class.metadata_column_fields.include?(attr.to_sym) return false unless (value = send(attr)) options = self.class.metadata_column_fields[attr.to_sym] || {} type = options[:type] || String return !value.to_i.zero? if type.ancestors.include?(Numeric) return !value.blank? end