On Sun, Dec 17, 2017 at 1:46 PM, Craig Russell <apache....@gmail.com> wrote:
>
>> On Dec 16, 2017, at 6:34 PM, Sam Ruby <ru...@intertwingly.net> wrote:
>>
>>> The code in the existing main.rb in get '/invite' sets several variables 
>>> that will be useful in discuss and vote. DRY says this code should only be 
>>> in one place. How can variables be shared among multiple get and post paths?
>>
>> Two basic approaches come to mind.  In the roster tool, there is code
>> in the models directory that return hashes.  Also in
>> www/roster/main.rb, you can find a helper that is called by multiple
>> views.
>
> What I'm trying to do is to get the @pmcs and @ppmcs variables sent to the 
> view from discuss, vote, and invite. The roster example shows no variables 
> outside the do... end blocks. The code to calculate these is simple but not 
> trivial.
>
> So would you recommend doing the calculation in the common code and setting 
> the @variables in the do... end block. E.g.
>
>   pmcs = ASF::Committee.pmcs.map(&:name).sort
>   ppmcs = ASF::Podling.list
>     .select {|podling| podling.status == 'current'}
>     .map(&:name).sort
>
> get '/discuss' do
>   @view = 'discuss'
>   @pmcs = pmcs
>   @ppmcs = ppmcs
>   _html :app
> end
>
> get '/vote' do
>   @view = 'vote'
>   @pmcs = pmcs
>   @ppmcs = ppmcs
>   _html :app
> end

I'm suggesting that you do something like @projects = projects()

Where projects() returns an object like {pmcs: [...], projects:
[...]}.  Of course, feel free to pick a different name, or to put the
method in a class, or chose a different structure returned by this
method.  But the basic idea is to create a method a

In the roster tool, Committee.serialize(name, env),
Committer.serialize(name, env), and Group.serialize(name) return
Hashes that are used by multiple get blocks.

> Craig L Russell
> Secretary, Apache Software Foundation
> c...@apache.org http://db.apache.org/jdo

- Sam Ruby

Reply via email to