You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by se...@apache.org on 2023/03/14 23:31:04 UTC
[whimsy] branch master updated (6dd19763 -> ff6e517a)
This is an automated email from the ASF dual-hosted git repository.
sebb pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
from 6dd19763 Clarify
new 3e0eda0a parse_entry: don't grab values from other keys
new ff6e517a Wrap output in array for easier handling
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
lib/whimsy/asf/member.rb | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
[whimsy] 01/02: parse_entry: don't grab values from other keys
Posted by se...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
commit 3e0eda0a94f8b10b34fd008eb2561ffa669450a7
Author: Sebb <se...@apache.org>
AuthorDate: Tue Mar 14 23:22:16 2023 +0000
parse_entry: don't grab values from other keys
Also allow list_entries to work as enumerator or with block
---
lib/whimsy/asf/member.rb | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/lib/whimsy/asf/member.rb b/lib/whimsy/asf/member.rb
index dd08bcba..dc7836c1 100644
--- a/lib/whimsy/asf/member.rb
+++ b/lib/whimsy/asf/member.rb
@@ -146,15 +146,17 @@ module ASF
keys_wanted = %i{email}
end
# init array to collect matching key values, even if repeated
- dict = {keys: keys_wanted.map{|k| [k,[]]}.to_h}
+ dict = keys_wanted.map{|k| [k,[]]}.to_h
current_entry = nil
entry.each do |line|
if line =~ %r{^ +([^:]+): *(.*)}
val = $2.strip # must be done first otherwise $2 is clobbered
key = key2sym($1)
if keys_wanted.include? key
- current_entry = dict[:keys][key]
+ current_entry = dict[key]
current_entry << val
+ else
+ current_entry = nil # new key, and not wanted
end
elsif current_entry and line.start_with? ' ' # needs to be indented at least this much to be a continuation line
value = line.strip
@@ -169,7 +171,8 @@ module ASF
# return all user entries, whether or not they have an id
# Params: keys_wanted: array of key names to extract and return
# Returns: array of [status, user name, availid or nil, entry lines, [keys]]
- def self.list_entries(keys_wanted=nil)
+ def self.list_entries(keys_wanted=nil, &block)
+ Enumerator.new do |y|
# split by heading underlines; drop text before first
ASF::Member.text.split("\n").slice_before {|a| a.start_with? '================'}.drop(1).each_with_index do |sect, index|
status = nil
@@ -198,14 +201,16 @@ module ASF
Wunderbar.error "Duplicate ids: #{ids} in #{name} entry"
end
if keys_wanted
- yield status, name, ids.first, entry, self.parse_entry(entry, keys_wanted.map!{|k| self.key2sym(k)})
+ y.yield status, name, ids.first, entry, self.parse_entry(entry, keys_wanted)
else
- yield status, name, ids.first, entry
+ y.yield status, name, ids.first, entry
end
end
+ else # can this happen?
+ raise ArgumentError, "Unexpected section with nil status!"
end
end
- nil
+ end.each(&block)
end
# An iterator that returns a list of ids and associated members.txt entries.
[whimsy] 02/02: Wrap output in array for easier handling
Posted by se...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
commit ff6e517afcae38198beec9ddcd1ab42637eea1c6
Author: Sebb <se...@apache.org>
AuthorDate: Tue Mar 14 23:30:58 2023 +0000
Wrap output in array for easier handling
---
lib/whimsy/asf/member.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/whimsy/asf/member.rb b/lib/whimsy/asf/member.rb
index dc7836c1..d94863d9 100644
--- a/lib/whimsy/asf/member.rb
+++ b/lib/whimsy/asf/member.rb
@@ -201,9 +201,9 @@ module ASF
Wunderbar.error "Duplicate ids: #{ids} in #{name} entry"
end
if keys_wanted
- y.yield status, name, ids.first, entry, self.parse_entry(entry, keys_wanted)
+ y.yield [status, name, ids.first, entry, self.parse_entry(entry, keys_wanted)]
else
- y.yield status, name, ids.first, entry
+ y.yield [status, name, ids.first, entry]
end
end
else # can this happen?