lib/keyrack/group.rb in keyrack-0.3.1 vs lib/keyrack/group.rb in keyrack-0.3.2

- old
+ new

@@ -188,21 +188,40 @@ end if sites.include?(site) raise GroupError, "site (#{site.name.inspect}, #{site.username.inspect}) already exists" end - sites << site + + index = sites.length + sites.each_with_index do |other, i| + if other.name > site.name || + (other.name == site.name && other.username > site.username) + index = i + break + end + end + sites.insert(index, site) + add_site_hooks_for(site) end def add_group_without_callbacks(group) if !group.is_a?(Group) raise GroupError, "group is not a Group" end if groups.has_key?(group.name) raise GroupError, "group already exists" end + + # wasteful but easy hash ordering groups[group.name] = group + keys = groups.keys.sort! + new_groups = keys.inject({}) do |hsh, key| + hsh[key] = groups[key] + hsh + end + @attributes['groups'] = new_groups + add_group_hooks_for(group) end def trigger(event) @after_event.each do |block|