Class: Neo4j::ActiveNode::Reflection::AssociationReflection

Inherits:
Object
  • Object
show all
Defined in:
lib/neo4j/active_node/reflection.rb

Overview

The actual reflection object that contains information about the given association. These should never need to be created manually, they will always be created by declaring a :has_many or :has_one association on a model.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(macro, name, association) ⇒ AssociationReflection

Returns a new instance of AssociationReflection.


49
50
51
52
53
# File 'lib/neo4j/active_node/reflection.rb', line 49

def initialize(macro, name, association)
  @macro        = macro
  @name         = name
  @association  = association
end

Instance Attribute Details

#associationObject (readonly)

The association object referenced by this reflection


47
48
49
# File 'lib/neo4j/active_node/reflection.rb', line 47

def association
  @association
end

#macroObject (readonly)

The type of association


44
45
46
# File 'lib/neo4j/active_node/reflection.rb', line 44

def macro
  @macro
end

#nameObject (readonly)

The name of the association


41
42
43
# File 'lib/neo4j/active_node/reflection.rb', line 41

def name
  @name
end

Instance Method Details

#class_nameObject

Returns the name of the target model


61
62
63
# File 'lib/neo4j/active_node/reflection.rb', line 61

def class_name
  @class_name ||= association.target_class.name
end

#collection?Boolean

Returns:


77
78
79
# File 'lib/neo4j/active_node/reflection.rb', line 77

def collection?
  macro == :has_many
end

#klassObject

Returns the target model


56
57
58
# File 'lib/neo4j/active_node/reflection.rb', line 56

def klass
  @klass ||= class_name.constantize
end

#rel_class_nameObject


69
70
71
# File 'lib/neo4j/active_node/reflection.rb', line 69

def rel_class_name
  @rel_class_name ||= association.relationship_class.name.to_s
end

#rel_klassObject


65
66
67
# File 'lib/neo4j/active_node/reflection.rb', line 65

def rel_klass
  @rel_klass ||= rel_class_name.constantize
end

#typeObject


73
74
75
# File 'lib/neo4j/active_node/reflection.rb', line 73

def type
  @type ||= association.relationship_type
end

#validate?Boolean

Returns:


81
82
83
# File 'lib/neo4j/active_node/reflection.rb', line 81

def validate?
  true
end