Class: Rasti::DB::Relations::Base
- Inherits:
-
Object
- Object
- Rasti::DB::Relations::Base
show all
- Includes:
- Sequel::Inflections
- Defined in:
- lib/rasti/db/relations/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, source_collection_class, options = {}) ⇒ Base
Returns a new instance of Base.
10
11
12
13
14
|
# File 'lib/rasti/db/relations/base.rb', line 10
def initialize(name, source_collection_class, options={})
@name = name
@source_collection_class = source_collection_class
@options = options
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
8
9
10
|
# File 'lib/rasti/db/relations/base.rb', line 8
def name
@name
end
|
#source_collection_class ⇒ Object
Returns the value of attribute source_collection_class.
8
9
10
|
# File 'lib/rasti/db/relations/base.rb', line 8
def source_collection_class
@source_collection_class
end
|
Instance Method Details
#from_many? ⇒ Boolean
40
41
42
|
# File 'lib/rasti/db/relations/base.rb', line 40
def from_many?
many_to_one? || many_to_many?
end
|
#from_one? ⇒ Boolean
36
37
38
|
# File 'lib/rasti/db/relations/base.rb', line 36
def from_one?
one_to_one? || one_to_many?
end
|
#join_relation_name(prefix) ⇒ Object
52
53
54
|
# File 'lib/rasti/db/relations/base.rb', line 52
def join_relation_name(prefix)
with_prefix prefix, name
end
|
#many_to_many? ⇒ Boolean
28
29
30
|
# File 'lib/rasti/db/relations/base.rb', line 28
def many_to_many?
self.class == ManyToMany
end
|
#many_to_one? ⇒ Boolean
24
25
26
|
# File 'lib/rasti/db/relations/base.rb', line 24
def many_to_one?
self.class == ManyToOne
end
|
#one_to_many? ⇒ Boolean
20
21
22
|
# File 'lib/rasti/db/relations/base.rb', line 20
def one_to_many?
self.class == OneToMany
end
|
#one_to_one? ⇒ Boolean
32
33
34
|
# File 'lib/rasti/db/relations/base.rb', line 32
def one_to_one?
self.class == OneToOne
end
|
#target_collection_class ⇒ Object
16
17
18
|
# File 'lib/rasti/db/relations/base.rb', line 16
def target_collection_class
@target_collection_class ||= options[:collection].is_a?(Class) ? options[:collection] : Consty.get(options[:collection] || camelize(pluralize(name)), source_collection_class)
end
|
#to_many? ⇒ Boolean
48
49
50
|
# File 'lib/rasti/db/relations/base.rb', line 48
def to_many?
one_to_many? || many_to_many?
end
|
#to_one? ⇒ Boolean
44
45
46
|
# File 'lib/rasti/db/relations/base.rb', line 44
def to_one?
one_to_one? || many_to_one?
end
|