Class: Graphoid::Relation
- Inherits:
-
Object
- Object
- Graphoid::Relation
show all
- Defined in:
- lib/graphoid/operators/relation.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(relation) ⇒ Relation
7
8
9
10
11
12
13
|
# File 'lib/graphoid/operators/relation.rb', line 7
def initialize(relation)
@name = relation.name.to_s
@camel_name = Utils.camelize(@name)
@inverse_name = Graphoid.driver.inverse_name_of(relation)
@klass = relation.class_name.constantize
@type = Graphoid.driver.relation_type(relation)
end
|
Instance Attribute Details
#inverse_name ⇒ Object
Returns the value of attribute inverse_name.
5
6
7
|
# File 'lib/graphoid/operators/relation.rb', line 5
def inverse_name
@inverse_name
end
|
#klass ⇒ Object
Returns the value of attribute klass.
5
6
7
|
# File 'lib/graphoid/operators/relation.rb', line 5
def klass
@klass
end
|
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/graphoid/operators/relation.rb', line 5
def name
@name
end
|
#type ⇒ Object
Returns the value of attribute type.
5
6
7
|
# File 'lib/graphoid/operators/relation.rb', line 5
def type
@type
end
|
Class Method Details
.relations_of(model) ⇒ Object
62
63
64
65
66
|
# File 'lib/graphoid/operators/relation.rb', line 62
def relations_of(model)
Graphoid.driver.relations_of(model)
end
|
Instance Method Details
#belongs? ⇒ Boolean
35
36
37
|
# File 'lib/graphoid/operators/relation.rb', line 35
def belongs?
belongs_to? || embedded_in?
end
|
#create(_, _, _) ⇒ Object
49
|
# File 'lib/graphoid/operators/relation.rb', line 49
def create(_, _, _); end
|
#embedded? ⇒ Boolean
43
44
45
|
# File 'lib/graphoid/operators/relation.rb', line 43
def embedded?
embeds_one? || embeds_many? || embedded_in?
end
|
#many? ⇒ Boolean
30
31
32
33
|
# File 'lib/graphoid/operators/relation.rb', line 30
def many?
has_many? || has_and_belongs_to_many? || through? || embeds_many?
end
|
#many_to_many? ⇒ Boolean
39
40
41
|
# File 'lib/graphoid/operators/relation.rb', line 39
def many_to_many?
has_and_belongs_to_many? || through?
end
|
#one? ⇒ Boolean
26
27
28
|
# File 'lib/graphoid/operators/relation.rb', line 26
def one?
belongs_to? || has_one? || embeds_one?
end
|
#precreate(_) ⇒ Object
47
|
# File 'lib/graphoid/operators/relation.rb', line 47
def precreate(_); end
|
#relation? ⇒ Boolean
22
23
24
|
# File 'lib/graphoid/operators/relation.rb', line 22
def relation?
true
end
|
#resolve(operation) ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'lib/graphoid/operators/relation.rb', line 51
def resolve(operation)
if one? || operation.operand.embedded?
return operation.operand.exec(operation.scope, operation.value)
end
if many?
return Graphoid.driver.relate_many(operation.scope, operation.operand, operation.value, operation.operator)
end
end
|