Module: Foobara::DetachedEntity::Concerns::Initialization

Includes:
Concern
Included in:
Foobara::DetachedEntity
Defined in:
foobara-0.0.125/projects/detached_entity/src/concerns/initialization.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

ALLOWED_OPTIONS =
Model::ALLOWED_OPTIONS + [:unloaded]

Instance Method Summary collapse

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Instance Method Details

#initialize(attributes = nil, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'foobara-0.0.125/projects/detached_entity/src/concerns/initialization.rb', line 19

def initialize(attributes = nil, options = {})
  invalid_options = options.keys - ALLOWED_OPTIONS

  unless invalid_options.empty?
    # :nocov:
    raise ArgumentError, "Invalid options #{invalid_options} expected only #{ALLOWED_OPTIONS}"
    # :nocov:
  end

  if options[:unloaded]
    options = options.except(:unloaded)

    unless options.key?(:validate)
      options[:validate] = false
    end

    unless options.key?(:skip_validations)
      options[:skip_validations] = true
    end

    unless options.key?(:ignore_unexpected_attributes)
      options[:ignore_unexpected_attributes] = false
    end

    unless options.key?(:mutable)
      options[:mutable] = false
    end

    super
    self.is_loaded = false
  else
    super
    self.is_loaded = true
  end
end