Something like this?

projects =
  pmcs.map {|pmc| [pmc, ASF::Committee.find(pmc).mail_list]}.to_h.
  merge(ppmcs.map {|ppmc| [ppmc, ASF::Podling.find(ppmc).mail_list]}.to_h)

Note:  ASF::Committee.find will never return nil (overall I consider
that a design flaw, but it will return back a committee object even
for PPMCs, which is why the code below doesn't error).

- Sam Ruby

On Thu, Dec 28, 2017 at 5:11 PM, Craig Russell <apache....@gmail.com> wrote:
> I've refactored a bit and now have:
>
> helpers do
>   def projectsForUser(userName)
>     pmcs = ASF::Committee.pmcs.map(&:name).sort
>     ppmcs =ASF::Podling.list
>       .select {|podling| podling.status == 'current'}
>       .map(&:name).sort
>     user = ASF::Person.find(userName)
>     committees = user.committees.map(&:name)
>     pmcs.select! {|pmc| committees.include?(pmc)}
>     ppmcs.select! {|ppmc|
>       committees.include?('incubator') | committees.include?(ppmc)}
>     mailList = {}
>     pmcs.each {|pmcName| pmc = ASF::Committee.find(pmcName)
>       if pmc
>         mailList[pmcName] = pmc.mail_list
>       end
>     }
>     ppmcs.each {|ppmcName| ppmc = ASF::Committee.find(ppmcName)
>       if ppmc
>         mailList[ppmcName] = ppmc.mail_list
>       end
>     }
>     hash = {
>       'pmcs' => pmcs,
>       'ppmcs' => ppmcs,
>       'pmcmail' => mailList
>     }
>   end
> end
>
> ...
>   @pmcs = projects['pmcs']
>   @ppmcs = projects['ppmcs']
>   @pmc_mail = projects['pmcmail']
>
> Seems to work ok.
>
> Can anyone suggest a more "conventional" way to construct the pmcmail hash? 
> Seems there should be a way to create a hash from two other hashes instead of 
> the each... if... routines.
>
> If there are more "conventional" ways to express the helpers projectForUser 
> I'd like to hear that also.
>
> Craig
>
>> On Dec 28, 2017, at 12:35 PM, Sam Ruby <ru...@intertwingly.net> wrote:
>>
>> On Thu, Dec 28, 2017 at 1:37 PM, Craig Russell <apache....@gmail.com> wrote:
>>> Dropping helpers. made it work.
>>>
>>> So is helpers a magic ruby thing? I read about ApplicationHelper but that's 
>>> not directly applicable.
>>
>> Instead of multiple inheritance, Ruby has single inheritance
>> classes... and modules.  Sinatra defines a module called
>> Sinatra::Helpers that is included in each view, and provides a
>> convenient syntax for you to add methods to that module.  You should
>> be able to achieve the same effect (with less magic) by adding methods
>> directly to Sinatra::Helpers, thus:
>>
>> module Sinatra::Helpers
>>  def pmcs
>>    ASF::Committee.pmcs.map(&:name).sort
>>  end
>>  def ppmcs
>>    ASF::Podling.list
>>    .select {|podling| podling.status == 'current'}
>>    .map(&:name).sort
>>  end
>> end
>>
>>> Craig
>>
>> - Sam Ruby
>>
>>>> On Dec 28, 2017, at 4:11 AM, Sam Ruby <ru...@intertwingly.net> wrote:
>>>>
>>>>>
>>>>>
>>>>> # get a complete list of PMC and PPMC names
>>>>> @pmcs = helpers.pmcs()
>>>>
>>>> Drop 'helpers.'
>>>>
>>>>> Any idea how to make this work?
>>>>>
>>>>> Craig
>>>>
>>>> - Sam Ruby
>>>
>>> Craig L Russell
>>> Secretary, Apache Software Foundation
>>> c...@apache.org http://db.apache.org/jdo
>>>
>
> Craig L Russell
> Secretary, Apache Software Foundation
> c...@apache.org http://db.apache.org/jdo
>

Reply via email to