Module: GroupedModel::GroupedInstanceMethods

Defined in:
lib/grouped_model.rb

Instance Method Summary collapse

Instance Method Details

#groupObject



123
124
125
126
127
128
129
# File 'lib/grouped_model.rb', line 123

def group
  if self.groups.length == 1
    self.groups.first
  else
    nil
  end
end

#group_id_listObject



147
148
149
# File 'lib/grouped_model.rb', line 147

def group_id_list
  self.groups.map(&:id).join(',')
end

#group_id_list=(ids) ⇒ Object



151
152
153
# File 'lib/grouped_model.rb', line 151

def group_id_list=(ids)
  self.groups = Group.find_these(ids.split(/,\s*/))
end

#has_group?(group) ⇒ Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/grouped_model.rb', line 139

def has_group?(group)
  return self.groups.include?(group)
end

#permit(group) ⇒ Object



143
144
145
# File 'lib/grouped_model.rb', line 143

def permit(group)
  self.groups << group unless self.has_group?(group)
end

#permitted_readersObject



135
136
137
# File 'lib/grouped_model.rb', line 135

def permitted_readers
  groups.any? ? Reader.in_groups(groups) : Reader.scoped({})
end

#visible?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/grouped_model.rb', line 131

def visible?
  groups.empty?
end

#visible_to?(reader) ⇒ Boolean

Returns:

  • (Boolean)


116
117
118
119
120
121
# File 'lib/grouped_model.rb', line 116

def visible_to?(reader)
  return true if self.groups.empty?
  return false if reader.nil?
  return true if reader.is_admin?
  return (reader.groups & self.groups).any?
end