if File.exist?(database_file)
yaml_config = ERB.new(IO.read(database_file)).result
database_config = YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(yaml_config) : YAML.load(yaml_config)
- adapters = database_config.values.map {|c| c['adapter']}.compact.uniq
+ adapters = database_config.values.filter_map {|c| c['adapter']}.uniq
if adapters.any?
adapters.each do |adapter|
case adapter
raise ActiveRecord::RecordNotFound if @issues.empty?
raise Unauthorized unless @issues.all?(&:visible?)
- @projects = @issues.collect(&:project).compact.uniq
+ @projects = @issues.filter_map(&:project).uniq
@project = @projects.first if @projects.size == 1
rescue ActiveRecord::RecordNotFound
render_404
@time_entry = @time_entries.first
end
- @projects = @time_entries.collect(&:project).compact.uniq
+ @projects = @time_entries.filter_map(&:project).uniq
@project = @projects.first if @projects.size == 1
@activities = @projects.map(&:activities).reduce(:&)
raise ActiveRecord::RecordNotFound if @time_entries.empty?
raise Unauthorized unless @time_entries.all? {|t| t.editable_by?(User.current)}
- @projects = @time_entries.collect(&:project).compact.uniq
+ @projects = @time_entries.filter_map(&:project).uniq
@project = @projects.first if @projects.size == 1
rescue ActiveRecord::RecordNotFound
render_404
# Render the error messages for the given objects
def error_messages_for(*objects)
- objects = objects.map {|o| o.is_a?(String) ? instance_variable_get("@#{o}") : o}.compact
+ objects = objects.filter_map {|o| o.is_a?(String) ? instance_variable_get("@#{o}") : o}
errors = objects.map {|o| o.errors.full_messages}.flatten
render_error_messages(errors)
end
end
messages.map do |message, items|
- ids = items.map(&:issue_to_id).compact
+ ids = items.filter_map(&:issue_to_id)
if ids.empty?
message
else
# Returns inheritance information for an inherited member role
def render_role_inheritance(member, role)
- content = member.role_inheritance(role).map do |h|
+ content = member.role_inheritance(role).filter_map do |h|
if h.is_a?(Project)
l(:label_inherited_from_parent_project)
elsif h.is_a?(Group)
l(:label_inherited_from_group, :name => h.name.to_s)
end
- end.compact.uniq
+ end.uniq
if content.present?
content_tag('em', content.join(", "), :class => "info")
value = column.value_object(item)
content =
if value.is_a?(Array)
- values = value.collect {|v| column_value(column, item, v)}.compact
+ values = value.filter_map {|v| column_value(column, item, v)}
safe_join(values, ', ')
else
column_value(column, item, value)
def csv_content(column, item)
value = column.value_object(item)
if value.is_a?(Array)
- value.collect {|v| csv_value(column, item, v)}.compact.join(', ')
+ value.filter_map {|v| csv_value(column, item, v)}.join(', ')
else
csv_value(column, item, value)
end
end
def render_changeset_changes
- changes = @changeset.filechanges.limit(1000).reorder('path').collect do |change|
+ changes = @changeset.filechanges.limit(1000).reorder('path').filter_map do |change|
case change.action
when 'A'
# Detects moved/copied files
else
change
end
- end.compact
+ end
tree = {}
changes.each do |change|
def role_inheritance(role)
member_roles.
select {|mr| mr.role_id == role.id && mr.inherited_from.present?}.
- map {|mr| mr.inherited_from_member_role.try(:member)}.
- compact.
+ filter_map {|mr| mr.inherited_from_member_role.try(:member)}.
map {|m| m.project == project ? m.principal : m.project}
end
return [] if available_columns.empty?
# preserve the column_names order
- cols = (has_default_columns? ? default_columns_names : column_names).collect do |name|
+ cols = (has_default_columns? ? default_columns_names : column_names).filter_map do |name|
available_columns.find {|col| col.name == name}
- end.compact
+ end
available_columns.select(&:frozen?) | cols
end
# commits.to_a.sort! {|x, y| x.last <=> y.last}
changes = Change.joins(:changeset).where("#{Changeset.table_name}.repository_id = ?", id).
select("committer, user_id, count(*) as count").group("committer, user_id")
- user_ids = changesets.map(&:user_id).compact.uniq
+ user_ids = changesets.filter_map(&:user_id).uniq
authors_names = User.where(:id => user_ids).inject({}) do |memo, user|
memo[user.id] = user.to_s
memo
private :save_revisions
def save_revision(rev)
- parents = (rev.parents || []).collect{|rp| find_changeset_by_name(rp)}.compact
+ parents = (rev.parents || []).filter_map{|rp| find_changeset_by_name(rp)}
changeset =
Changeset.create(
:repository => self,
(db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i|
scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re|
transaction do
- parents = (re.parents || []).collect do |rp|
+ parents = (re.parents || []).filter_map do |rp|
find_changeset_by_name(scmid_for_inserting_db(rp))
- end.compact
+ end
cs = Changeset.create(:repository => self,
:revision => re.revision,
:scmid => scmid_for_inserting_db(re.scmid),
def latest_changesets(path, rev, limit=10)
revisions = scm.revisions(path, rev, nil, :limit => limit)
if revisions
- identifiers = revisions.collect(&:identifier).compact
+ identifiers = revisions.filter_map(&:identifier)
changesets.where(:revision => identifiers).reorder("committed_on DESC").includes(:repository, :user).to_a
else
[]
entries_with_identifier =
entries.select {|entry| entry.lastrev && entry.lastrev.identifier.present?}
- identifiers = entries_with_identifier.map {|entry| entry.lastrev.identifier}.compact.uniq
+ identifiers = entries_with_identifier.filter_map {|entry| entry.lastrev.identifier}.uniq
if identifiers.any?
changesets_by_identifier =
changesets.where(:revision => identifiers).
end
def permissions=(perms)
- perms = perms.collect {|p| p.to_sym unless p.blank?}.compact.uniq if perms
+ perms = perms.filter_map {|p| p.to_sym unless p.blank?}.uniq if perms
write_attribute(:permissions, perms)
end
def possible_values_records(custom_field, object=nil)
if object.is_a?(Array)
- projects = object.map {|o| o.respond_to?(:project) ? o.project : nil}.compact.uniq
+ projects = object.filter_map {|o| o.respond_to?(:project) ? o.project : nil}.uniq
projects.map {|project| possible_values_records(custom_field, project)}.reduce(:&) || []
elsif object.respond_to?(:project) && object.project
scope = object.project.users
def possible_values_records(custom_field, object=nil, all_statuses=false)
if object.is_a?(Array)
- projects = object.map {|o| o.respond_to?(:project) ? o.project : nil}.compact.uniq
+ projects = object.filter_map {|o| o.respond_to?(:project) ? o.project : nil}.uniq
projects.map {|project| possible_values_records(custom_field, project)}.reduce(:&) || []
elsif object.respond_to?(:project) && object.project
scope = object.project.shared_versions
# Returns the distinct versions of the issues that belong to +project+
def project_versions(project)
- project_issues(project).collect(&:fixed_version).compact.uniq
+ project_issues(project).filter_map(&:fixed_version).uniq
end
# Returns the issues that belong to +project+ and are assigned to +version+
@scope.includes(:activity).
reorder(nil).
group(@criteria.collect{|criteria| @available_criteria[criteria][:sql]} + time_columns).
- joins(@criteria.collect{|criteria| @available_criteria[criteria][:joins]}.compact).
+ joins(@criteria.filter_map{|criteria| @available_criteria[criteria][:joins]}).
sum(:hours).each do |hash, hours|
h = {'hours' => hours}
(@criteria + time_columns).each_with_index do |name, i|
def self.block_options(blocks_in_use=[])
options = []
blocks.each do |block, block_options|
- indexes = blocks_in_use.map do |n|
+ indexes = blocks_in_use.filter_map do |n|
if n =~ /\A#{block}(__(\d+))?\z/
$2.to_i
end
- end.compact
+ end
occurs = indexes.size
block_id = indexes.any? ? "#{block}__#{indexes.max + 1}" : block
end
def revisions
- revisions ||= Revisions.new(collect{|entry| entry.lastrev}.compact)
+ revisions ||= Revisions.new(filter_map{|entry| entry.lastrev})
end
end
klass = scope.singularize.camelcase.constantize
results_by_scope[scope] += klass.search_results_from_ids(scope_and_ids.map(&:last))
end
- result_ids_to_load.map do |scope, id|
+ result_ids_to_load.filter_map do |scope, id|
results_by_scope[scope].detect {|record| record.id == id}
- end.compact
+ end
end
# Returns the results ids, sorted by rank
get(:index, :params => {:sort => 'assigned_to'})
assert_response :success
- assignees = issues_in_list.map(&:assigned_to).compact
+ assignees = issues_in_list.filter_map(&:assigned_to)
assert_equal assignees.sort, assignees
assert_select 'table.issues.sort-by-assigned-to.sort-asc'
end
get(:index, :params => {:sort => 'assigned_to:desc'})
assert_response :success
- assignees = issues_in_list.map(&:assigned_to).compact
+ assignees = issues_in_list.filter_map(&:assigned_to)
assert_equal assignees.sort.reverse, assignees
assert_select 'table.issues.sort-by-assigned-to.sort-desc'
end
q.sort_criteria = [[c.name.to_s, 'asc']]
issues = q.issues
values =
- issues.collect do |i|
+ issues.filter_map do |i|
begin
Kernel.Float(i.custom_value_for(c.custom_field).to_s)
rescue
nil
end
- end.compact
+ end
assert !values.empty?
assert_equal values.sort, values
end