class GitSu::UserList
Constants
- MATCH_STRATEGIES
Public Class Methods
new(user_file)
click to toggle source
# File lib/gitsu/user_list.rb, line 35 def initialize(user_file) @user_file = user_file end
Public Instance Methods
add(user)
click to toggle source
# File lib/gitsu/user_list.rb, line 39 def add(user) @user_file.write(user) end
find(*search_terms)
click to toggle source
# File lib/gitsu/user_list.rb, line 47 def find(*search_terms) all_users = list searches = all_matching_users(all_users, search_terms) searches.each do |search| if search.matches.empty? raise "No user found matching '#{search.term}'" end end find_unique_combination(searches) or raise "Couldn't find a combination of users matching #{search_terms.quote.to_sentence}" end
list()
click to toggle source
# File lib/gitsu/user_list.rb, line 43 def list @user_file.read end
Private Instance Methods
all_matching_users(all_users, search_terms)
click to toggle source
# File lib/gitsu/user_list.rb, line 67 def all_matching_users(all_users, search_terms) searches = search_terms.map {|search_term| Search.new(search_term)} searches.each do |search| MATCH_STRATEGIES.each do |strategy| search.matches += all_users.select { |user| strategy.call(search.term, user) } end search.matches.uniq! end end
find_unique_combination(searches)
click to toggle source
# File lib/gitsu/user_list.rb, line 77 def find_unique_combination(searches) searches = searches.clone # Generate all combinations combinations = [[]] searches.each do |search| previous_combos = combinations.clone combinations = [] previous_combos.each do |combo| search.matches.each do |match| combo_extension = combo.clone combo_extension << match combinations << combo_extension end end end combinations.find do |combo| combo.uniq.size == combo.size end end