class Object
Public Instance Methods
arel_attribute(name)
click to toggle source
Returns an Arel::Node that is used to query a field. In case that attribute is a column or if current model hasn't initialized 'no_sqlize' keeps Rails' behavior.
# File lib/quantum_fields/active_record_patch.rb, line 23 def arel_attribute(name) if klass.column_names.include?(name.to_s) || !klass.respond_to?(:fields_column) klass.arel_attribute(name, table) else QuantumFields::Support.field_node klass.arel_table[klass.fields_column], name end end
attribute_alias(name)
click to toggle source
Returns the original name or quantum field for the alias name
# File lib/quantum_fields/active_record_patch.rb, line 42 def attribute_alias(name) if column_names.include?(name.to_s) || !respond_to?(:fields_column) attribute_aliases[name.to_s] else name end end
attribute_alias?(new_name)
click to toggle source
Is new_name
an alias or a quantum field?
# File lib/quantum_fields/active_record_patch.rb, line 35 def attribute_alias?(new_name) attribute_aliases.key?(new_name.to_s) || (!['all', 'star', ' ', '*'].include?(new_name.to_s) && respond_to?(:fields_column) && !column_names.include?(new_name.to_s)) end
build(attribute, value)
click to toggle source
Builds an binded Arel operation, injecting json operator if necessary
# File lib/quantum_fields/active_record_patch.rb, line 5 def build(attribute, value) if table.type(attribute.name).force_equality?(value) bind = build_bind_attribute(attribute.name, value) attribute.eq(bind) elsif table.send('klass').respond_to?(:fields_column) && !table.send('klass').column_names.include?(attribute.name) op = QuantumFields::Support.field_node(table.send('klass').arel_table[table.send('klass').fields_column], attribute.name) attribute.name = table.send('klass').fields_column.to_s bind = build_bind_attribute(op, value) op.eq(bind) else handler_for(value).call(attribute, value) end end