Class: Component
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Component
show all
- Defined in:
- lib/app/models/component.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#component ⇒ Object
Returns the value of attribute component.
3
4
5
|
# File 'lib/app/models/component.rb', line 3
def component
@component
end
|
Class Method Details
.base_class ⇒ Object
91
92
93
|
# File 'lib/app/models/component.rb', line 91
def base_class
class_of_active_record_descendant(self)
end
|
.class_of_active_record_descendant(klass) ⇒ Object
95
96
97
98
99
100
101
102
103
|
# File 'lib/app/models/component.rb', line 95
def class_of_active_record_descendant(klass)
if klass.superclass == Component || klass.superclass.abstract_class?
klass
elsif klass.superclass.nil?
raise ActiveRecordError, "#{name} doesn't belong in a hierarchy descending from ActiveRecord"
else
class_of_active_record_descendant(klass.superclass)
end
end
|
.compute_table_name ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/app/models/component.rb', line 77
def compute_table_name
base = base_class
if self == base
if parent < Component && !parent.abstract_class?
contained = parent.table_name
contained = contained.singularize if parent.pluralize_table_names
contained << '_'
end
"#{full_table_name_prefix}#{contained}#{undecorated_table_name(name)}#{table_name_suffix}"
else
base.table_name
end
end
|
.reset_table_name ⇒ Object
72
73
74
|
# File 'lib/app/models/component.rb', line 72
def reset_table_name self.table_name = compute_table_name
end
|
.table_name ⇒ Object
68
69
70
|
# File 'lib/app/models/component.rb', line 68
def table_name
reset_table_name
end
|
Instance Method Details
#add_component(sub_component) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/app/models/component.rb', line 22
def add_component(sub_component)
if sub_component.is_a? Event
self.component.events << sub_component.component
elsif sub_component.is_a? Todo
self.component.todos << sub_component.component
elsif sub_component.is_a? Journal
self.component.journals << sub_component.component
elsif sub_component.is_a? Alarm
self.component.alarms << sub_component.component
elsif sub_component.is_a? FreeBusy
self.component.freebusys << sub_component.component
end
self.ical = self.component.to_rfc2445_string
end
|
#belongs_to ⇒ Object
56
57
58
|
# File 'lib/app/models/component.rb', line 56
def belongs_to
self.class.reflect_on_all_associations.select {|a| a.macro == :belongs_to }
end
|
#component_names ⇒ Object
37
38
39
40
41
|
# File 'lib/app/models/component.rb', line 37
def component_names
self.class.reflect_on_all_associations.map do |a|
a.name if a.klass.ancestors.include?(Component) && (a.macro != :belongs_to)
end.compact
end
|
#components ⇒ Object
43
44
45
|
# File 'lib/app/models/component.rb', line 43
def components
component_names.map {|co| self.send(co).map {|d| d.component }}.flatten
end
|
#reset_component ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/app/models/component.rb', line 47
def reset_component
self.ical = nil
self.component = nil
set_component
self.components.each {|co|
self.component.add_subcomponent(co)
}
end
|
#set_component ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/app/models/component.rb', line 7
def set_component
[[Calendar, RiCal.Calendar], [Event, RiCal.Event], [Todo, RiCal.Todo],
[Journal, RiCal.Journal], [Alarm, RiCal.Alarm], [FreeBusy, RiCal.Freebusy]].each {|comp|
if self.is_a? comp[0]
@component ||= comp[1]
break
end
}
self.ical = @component.to_rfc2445_string if self.ical.nil?
@component
end
|
#to_ical(options = {}) ⇒ Object
106
107
108
|
# File 'lib/app/models/component.rb', line 106
def to_ical(options ={})
self.ical.to_rfc2445_string
end
|
#trigger_parent_component ⇒ Object
60
61
62
63
64
|
# File 'lib/app/models/component.rb', line 60
def trigger_parent_component
self.belongs_to.each {|asc|
self.send(asc.name).add_component(self) unless self.send(asc.name).nil?
} if self.new_record?
end
|