Class: ActiveEntity::Reflection::EmbeddedAssociationReflection

Inherits:
MacroEmbeddedReflection show all
Defined in:
lib/active_entity/reflection.rb

Overview

Holds all the metadata about an association as it was specified in the Active Entity class.

Constant Summary collapse

VALID_AUTOMATIC_INVERSE_MACROS =
[:embeds_many, :embeds_one, :embedded_in]

Instance Attribute Summary collapse

Attributes inherited from MacroEmbeddedReflection

#active_entity, #name, #options

Instance Method Summary collapse

Methods inherited from MacroEmbeddedReflection

#==, #klass

Methods inherited from AbstractEmbeddedReflection

#build_association, #check_validity_of_inverse!, #class_name, #embedded?, #inverse_of, #through_reflection?

Methods inherited from AbstractReflection

#embedded?

Constructor Details

#initialize(name, scope, options, active_entity) ⇒ EmbeddedAssociationReflection

Returns a new instance of EmbeddedAssociationReflection.



278
279
280
281
282
283
284
285
# File 'lib/active_entity/reflection.rb', line 278

def initialize(name, scope, options, active_entity)
  super
  @constructable = calculate_constructable(macro, options)

  if options[:class_name] && options[:class_name].class == Class
    raise ArgumentError, "A class was passed to `:class_name` but we are expecting a string."
  end
end

Instance Attribute Details

#parent_reflectionObject

Reflection



276
277
278
# File 'lib/active_entity/reflection.rb', line 276

def parent_reflection
  @parent_reflection
end

#typeObject (readonly)

Returns the value of attribute type.



275
276
277
# File 'lib/active_entity/reflection.rb', line 275

def type
  @type
end

Instance Method Details

#association_classObject

Raises:

  • (NotImplementedError)


334
# File 'lib/active_entity/reflection.rb', line 334

def association_class; raise NotImplementedError; end

#check_validity!Object



291
292
293
# File 'lib/active_entity/reflection.rb', line 291

def check_validity!
  check_validity_of_inverse!
end

#collection?Boolean

Returns whether or not this association reflection is for a collection association. Returns true if the macro is either has_many or has_and_belongs_to_many, false otherwise.

Returns:

  • (Boolean)


311
312
313
# File 'lib/active_entity/reflection.rb', line 311

def collection?
  false
end

#compute_class(name) ⇒ Object

:nodoc:



271
272
273
# File 'lib/active_entity/reflection.rb', line 271

def compute_class(name)
  active_entity.send(:compute_type, name)
end

#constructable?Boolean

:nodoc:

Returns:

  • (Boolean)


287
288
289
# File 'lib/active_entity/reflection.rb', line 287

def constructable? # :nodoc:
  @constructable
end

#embedded_in?Boolean

Returns true if self is a belongs_to reflection.

Returns:

  • (Boolean)


329
# File 'lib/active_entity/reflection.rb', line 329

def embedded_in?; false; end

#embeds_one?Boolean

Returns true if self is a has_one reflection.

Returns:

  • (Boolean)


332
# File 'lib/active_entity/reflection.rb', line 332

def embeds_one?; false; end

#extensionsObject



338
339
340
# File 'lib/active_entity/reflection.rb', line 338

def extensions
  Array(options[:extend])
end

#has_inverse?Boolean

Returns:

  • (Boolean)


299
300
301
# File 'lib/active_entity/reflection.rb', line 299

def has_inverse?
  inverse_name
end

#macroObject

Returns the macro type.

has_many :clients returns :has_many

Raises:

  • (NotImplementedError)


306
# File 'lib/active_entity/reflection.rb', line 306

def macro; raise NotImplementedError; end

#nested?Boolean

Returns:

  • (Boolean)


295
296
297
# File 'lib/active_entity/reflection.rb', line 295

def nested?
  false
end

#validate?Boolean

Returns whether or not the association should be validated as part of the parent’s validation.

Unless you explicitly disable validation with validate: false, validation will take place when:

  • you explicitly enable validation; validate: true

  • you use autosave; autosave: true

  • the association is a has_many association

Returns:

  • (Boolean)


324
325
326
# File 'lib/active_entity/reflection.rb', line 324

def validate?
  !!options[:validate]
end