Module: NoBrainer::Document::Types

Extended by:
ActiveSupport::Concern
Defined in:
lib/no_brainer/document/types.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load_type_extensions(model) ⇒ Object



122
123
124
125
126
127
128
129
130
# File 'lib/no_brainer/document/types.rb', line 122

def load_type_extensions(model)
  unless loaded_extensions.include?(model)
    begin
      require File.join(File.dirname(__FILE__), 'types', model.name.underscore)
    rescue LoadError
    end
    loaded_extensions << model
  end
end

Instance Method Details

#add_type_errorsObject



9
10
11
12
13
14
# File 'lib/no_brainer/document/types.rb', line 9

def add_type_errors
  return unless @pending_type_errors
  @pending_type_errors.each do |name, error|
    errors.add(name, :invalid_type, **error.error)
  end
end

#assign_attributes(attrs, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/no_brainer/document/types.rb', line 16

def assign_attributes(attrs, options={})
  super
  if options[:from_db]
    @_attributes = Hash[@_attributes.map do |k,v|
      [k, self.class.cast_db_to_model_for(k, v)]
    end].with_indifferent_access
  end
end