module QuantumFields::ClassMethods

This module contains the methods called within the Model to initialize and to manage how the other methods should behave on the given context.

Public Instance Methods

no_sqlize(args = {}) click to toggle source

Method called in the model context to initialize behavior and pass configuration options into quantum_fields. You can use a custom column for your fields and a custom column for your injected validation rules. Initializing the gem behavior on default 'quantum_fields' and 'quantum_rules' columns:

> no_sqlize

Initializing the gem behavior on default 'quantum_rules' column and a custom fields_column 'my_json_field'

> no_sqlize fields_column: :my_json_field

Initializing the gem behavior on default 'quantum_fields' column and a custom rules_column 'my_json_field', affecting from where to pull injected validations:

> no_sqlize rules_column: :my_json_field

# File lib/quantum_fields.rb, line 32
    def no_sqlize(args = {})
      class_eval <<-RUBY, __FILE__, __LINE__+1
        def self.fields_column
          :#{args[:fields_column] || :quantum_fields}
        end
        def self.rules_column
          :#{args[:rules_column] || :quantum_rules}
        end
        def as_json(*args)
          super.except(self.class.fields_column.to_s, self.class.rules_column.to_s).tap do |hash|
            self.try(:quantum_fields)&.each do |key, value|
              hash[key] = value
            end
          end
        end
      RUBY
      include QuantumFields::NoSqlize
      include QuantumFields::ValidationInjector
    end