class Study
include Contracts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Class Methods
of_group_and_its_subgroups(group)
click to toggle source
Contract Group
=> ActiveRecord::Relation
# File lib/tmis/engine/models/study.rb, line 19 def self.of_group_and_its_subgroups(group) where_groups_or_subgroups(group.id, Subgroup.where(group_id: group.id)) end
of_groups_and_its_subgroups(groups)
click to toggle source
Use Model#scoped instead of Model#all
Contract ActiveRecord::Relation => ActiveRecord::Relation::ActiveRecord_Relation_Group
# File lib/tmis/engine/models/study.rb, line 14 def self.of_groups_and_its_subgroups(groups) where_groups_or_subgroups(groups.select(:id), Subgroup.where(group_id: groups.select(:id))) end
Private Class Methods
where_groups_or_subgroups(ids_of_groups, ids_of_subroups)
click to toggle source
# File lib/tmis/engine/models/study.rb, line 52 def self.where_groups_or_subgroups(ids_of_groups, ids_of_subroups) where('(groupable_type = "Group" AND groupable_id in (?)) OR (groupable_type = "Subgroup" AND groupable_id in (?))', ids_of_groups, ids_of_subroups) end
Public Instance Methods
get_group()
click to toggle source
# File lib/tmis/engine/models/study.rb, line 26 def get_group groupable.get_group end
to_group?()
click to toggle source
# File lib/tmis/engine/models/study.rb, line 30 def to_group? groupable_type == 'Group' end
to_s()
click to toggle source
# File lib/tmis/engine/models/study.rb, line 38 def to_s begin if to_subgroup? "#{subject.title}\n#{lecturer}" + " (#{groupable.number}п)" else "#{subject.title}\n#{lecturer}" end rescue #FIXME 'ERROR' end end
to_subgroup?()
click to toggle source
# File lib/tmis/engine/models/study.rb, line 34 def to_subgroup? groupable_type == 'Subgroup' end
validate()
click to toggle source
# File lib/tmis/engine/models/study.rb, line 23 def validate end