Module: RTM::AR::Sugar::Association::HashAccess

Included in:
Association
Defined in:
lib/rtm/activerecord/sugar/association/hash_access.rb

Overview

This module implements methods for Hash-like access in Associations.

Instance Method Summary collapse

Instance Method Details

#[](type_reference = :any) ⇒ Object

Returns the roles of the association which match the given role type. The role type can be specified as String-reference or as Topic.



10
11
12
13
14
15
16
17
18
19
# File 'lib/rtm/activerecord/sugar/association/hash_access.rb', line 10

def [](type_reference=:any)
  return roles if type_reference == :any
  return roles unless type_reference
  if type_reference.is_a? String
    roles.select{|o| o.type == topic_map.get(type_reference)}
  else
    # assume topics are given
    roles.select{|o| o.type == type_reference}
  end
end