Class: ActiveEntity::Reflection::EmbeddedAssociationReflection
- Inherits:
-
MacroEmbeddedReflection
- Object
- AbstractReflection
- AbstractEmbeddedReflection
- MacroEmbeddedReflection
- ActiveEntity::Reflection::EmbeddedAssociationReflection
- Defined in:
- lib/active_entity/reflection.rb
Overview
Holds all the metadata about an association as it was specified in the Active Entity class.
Direct Known Subclasses
EmbeddedInReflection, EmbedsManyReflection, EmbedsOneReflection
Constant Summary collapse
- VALID_AUTOMATIC_INVERSE_MACROS =
[:embeds_many, :embeds_one, :embedded_in]
Instance Attribute Summary collapse
-
#parent_reflection ⇒ Object
Reflection.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from MacroEmbeddedReflection
#active_entity, #name, #options
Instance Method Summary collapse
- #association_class ⇒ Object
- #check_validity! ⇒ Object
-
#collection? ⇒ Boolean
Returns whether or not this association reflection is for a collection association.
-
#compute_class(name) ⇒ Object
:nodoc:.
-
#constructable? ⇒ Boolean
:nodoc:.
-
#embedded_in? ⇒ Boolean
Returns
true
ifself
is abelongs_to
reflection. -
#embeds_one? ⇒ Boolean
Returns
true
ifself
is ahas_one
reflection. - #extensions ⇒ Object
- #has_inverse? ⇒ Boolean
-
#initialize(name, scope, options, active_entity) ⇒ EmbeddedAssociationReflection
constructor
A new instance of EmbeddedAssociationReflection.
-
#macro ⇒ Object
Returns the macro type.
- #nested? ⇒ Boolean
-
#validate? ⇒ Boolean
Returns whether or not the association should be validated as part of the parent’s validation.
Methods inherited from MacroEmbeddedReflection
Methods inherited from AbstractEmbeddedReflection
#build_association, #check_validity_of_inverse!, #class_name, #embedded?, #inverse_of, #through_reflection?
Methods inherited from AbstractReflection
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, , active_entity) super @constructable = calculate_constructable(macro, ) if [:class_name] && [: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_reflection ⇒ Object
Reflection
276 277 278 |
# File 'lib/active_entity/reflection.rb', line 276 def parent_reflection @parent_reflection end |
#type ⇒ Object (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_class ⇒ Object
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.
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:
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.
329 |
# File 'lib/active_entity/reflection.rb', line 329 def ; false; end |
#embeds_one? ⇒ Boolean
Returns true
if self
is a has_one
reflection.
332 |
# File 'lib/active_entity/reflection.rb', line 332 def ; false; end |
#extensions ⇒ Object
338 339 340 |
# File 'lib/active_entity/reflection.rb', line 338 def extensions Array([:extend]) end |
#has_inverse? ⇒ Boolean
299 300 301 |
# File 'lib/active_entity/reflection.rb', line 299 def has_inverse? inverse_name end |
#macro ⇒ Object
Returns the macro type.
has_many :clients
returns :has_many
306 |
# File 'lib/active_entity/reflection.rb', line 306 def macro; raise NotImplementedError; end |
#nested? ⇒ 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
324 325 326 |
# File 'lib/active_entity/reflection.rb', line 324 def validate? !![:validate] end |