Module: Relationships
Defined Under Namespace
Modules: ClassMethods
Classes: BelongsTo, HasAndBelongsToMany, HasMany, HasOne, Relationship
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
5
6
7
|
# File 'lib/active_mocker/active_record/relationships.rb', line 5
def self.included(base)
base.extend(ClassMethods)
end
|
Instance Method Details
#belongs_to(*args) ⇒ Object
87
88
89
90
|
# File 'lib/active_mocker/active_record/relationships.rb', line 87
def belongs_to(*args)
@belongs_to ||= []
@belongs_to.push BelongsTo.new(args.shift, args)
end
|
#collections ⇒ Object
24
25
26
|
# File 'lib/active_mocker/active_record/relationships.rb', line 24
def collections
has_and_belongs_to_many + has_many
end
|
#has_and_belongs_to_many(*args) ⇒ Object
96
97
98
99
|
# File 'lib/active_mocker/active_record/relationships.rb', line 96
def has_and_belongs_to_many(*args)
@has_and_belongs_to_many ||= []
@has_and_belongs_to_many.push HasAndBelongsToMany.new(args.shift, args)
end
|
#has_many(*args) ⇒ Object
71
72
73
74
|
# File 'lib/active_mocker/active_record/relationships.rb', line 71
def has_many(*args)
@has_many ||= []
@has_many.push HasMany.new(args.shift, self.name, args)
end
|
#has_one(*args) ⇒ Object
79
80
81
82
|
# File 'lib/active_mocker/active_record/relationships.rb', line 79
def has_one(*args)
@has_one ||= []
@has_one.push HasOne.new(args.shift, args)
end
|
#relationships ⇒ Object
13
14
15
16
17
18
|
# File 'lib/active_mocker/active_record/relationships.rb', line 13
def relationships
OpenStruct.new({has_many: @has_many ||= [],
has_one: @has_one ||= [],
belongs_to: @belongs_to ||= [],
has_and_belongs_to_many: @has_and_belongs_to_many ||= []})
end
|
#single_relationships ⇒ Object
20
21
22
|
# File 'lib/active_mocker/active_record/relationships.rb', line 20
def single_relationships
belongs_to + has_one
end
|