You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by Sebastian Bazley <se...@apache.org> on 2016/03/15 17:10:14 UTC

[whimsy.git] [1/1] Commit 6c2b651: to_h is relatively new; allow code to run on older Ruby versions

Commit 6c2b651834355a5e677906b939449e43fb6b38e3:
    to_h is relatively new; allow code to run on older Ruby versions


Branch: refs/heads/master
Author: Sebb <se...@apache.org>
Committer: Sebb <se...@apache.org>
Pusher: sebb <se...@apache.org>

------------------------------------------------------------
www/roster/models/group.rb                                   | ++++++++ ---
------------------------------------------------------------
22 changes: 16 additions, 6 deletions.
------------------------------------------------------------


diff --git a/www/roster/models/group.rb b/www/roster/models/group.rb
index acc40e9..0015b1d 100644
--- a/www/roster/models/group.rb
+++ b/www/roster/models/group.rb
@@ -8,16 +8,26 @@ def self.list
     groups = ASF::Group.list.map(&:id)
     groups -= ASF::Committee.list.map(&:id)
     groups.map! {|group| [group, "LDAP group"]}
-
     # add services...
     groups += ASF::Service.list.map {|service| [service, "LDAP service"]}
 
     # add authorization (asf and pit)
-    groups += ASF::Authorization.new('asf').to_h.
-      map {|id, list| [id, "ASF Auth"]}
-
-    groups += ASF::Authorization.new('pit').to_h.
-      map {|id, list| [id, "PIT Auth"]}
+    begin
+      groups += ASF::Authorization.new('asf').to_h.
+        map {|id, list| [id, "ASF Auth"]}
+    rescue # in case to_h does not work
+      ASF::Authorization.new('asf').each do |id,list|
+        groups += [[id, "ASF Auth"]]
+      end
+    end
+    begin
+      groups += ASF::Authorization.new('pit').to_h.
+        map {|id, list| [id, "PIT Auth"]}
+    rescue # in case to_h does not work
+      ASF::Authorization.new('pit').each do |id,list|
+        groups += [[id, "PIT Auth"]]
+      end
+    end
 
     groups.sort
   end

Re: [whimsy.git] [1/1] Commit 6c2b651: to_h is relatively new; allow code to run on older Ruby versions

Posted by Sam Ruby <ru...@intertwingly.net>.
On Tue, Mar 15, 2016 at 1:06 PM, sebb <se...@gmail.com> wrote:
> Thanks - I keep learning new ways to work with Ruby...

Keep doing what you are doing. You are doing fine.  If I see something
broken, I'll fix it.  If I see a better way, I'll mention it.

After all, you've done the same for me on both counts.

- Sam Ruby

Re: [whimsy.git] [1/1] Commit 6c2b651: to_h is relatively new; allow code to run on older Ruby versions

Posted by sebb <se...@gmail.com>.
Thanks - I keep learning new ways to work with Ruby...

On 15 March 2016 at 16:41, Sam Ruby <ru...@intertwingly.net> wrote:
> On Tue, Mar 15, 2016 at 12:10 PM, Sebastian Bazley <se...@apache.org> wrote:
>> Commit 6c2b651834355a5e677906b939449e43fb6b38e3:
>>     to_h is relatively new; allow code to run on older Ruby versions
>
> Looks messy.  :-)  I propose the following as a cleaner implementation:
>
> https://github.com/apache/whimsy/commit/a8acbc8b6f7a64a1372348cc62b8c796c7f077c8
>
> - Sam Ruby
>
>> Branch: refs/heads/master
>> Author: Sebb <se...@apache.org>
>> Committer: Sebb <se...@apache.org>
>> Pusher: sebb <se...@apache.org>
>>
>> ------------------------------------------------------------
>> www/roster/models/group.rb                                   | ++++++++ ---
>> ------------------------------------------------------------
>> 22 changes: 16 additions, 6 deletions.
>> ------------------------------------------------------------
>>
>>
>> diff --git a/www/roster/models/group.rb b/www/roster/models/group.rb
>> index acc40e9..0015b1d 100644
>> --- a/www/roster/models/group.rb
>> +++ b/www/roster/models/group.rb
>> @@ -8,16 +8,26 @@ def self.list
>>      groups = ASF::Group.list.map(&:id)
>>      groups -= ASF::Committee.list.map(&:id)
>>      groups.map! {|group| [group, "LDAP group"]}
>> -
>>      # add services...
>>      groups += ASF::Service.list.map {|service| [service, "LDAP service"]}
>>
>>      # add authorization (asf and pit)
>> -    groups += ASF::Authorization.new('asf').to_h.
>> -      map {|id, list| [id, "ASF Auth"]}
>> -
>> -    groups += ASF::Authorization.new('pit').to_h.
>> -      map {|id, list| [id, "PIT Auth"]}
>> +    begin
>> +      groups += ASF::Authorization.new('asf').to_h.
>> +        map {|id, list| [id, "ASF Auth"]}
>> +    rescue # in case to_h does not work
>> +      ASF::Authorization.new('asf').each do |id,list|
>> +        groups += [[id, "ASF Auth"]]
>> +      end
>> +    end
>> +    begin
>> +      groups += ASF::Authorization.new('pit').to_h.
>> +        map {|id, list| [id, "PIT Auth"]}
>> +    rescue # in case to_h does not work
>> +      ASF::Authorization.new('pit').each do |id,list|
>> +        groups += [[id, "PIT Auth"]]
>> +      end
>> +    end
>>
>>      groups.sort
>>    end

Re: [whimsy.git] [1/1] Commit 6c2b651: to_h is relatively new; allow code to run on older Ruby versions

Posted by Sam Ruby <ru...@intertwingly.net>.
On Tue, Mar 15, 2016 at 12:10 PM, Sebastian Bazley <se...@apache.org> wrote:
> Commit 6c2b651834355a5e677906b939449e43fb6b38e3:
>     to_h is relatively new; allow code to run on older Ruby versions

Looks messy.  :-)  I propose the following as a cleaner implementation:

https://github.com/apache/whimsy/commit/a8acbc8b6f7a64a1372348cc62b8c796c7f077c8

- Sam Ruby

> Branch: refs/heads/master
> Author: Sebb <se...@apache.org>
> Committer: Sebb <se...@apache.org>
> Pusher: sebb <se...@apache.org>
>
> ------------------------------------------------------------
> www/roster/models/group.rb                                   | ++++++++ ---
> ------------------------------------------------------------
> 22 changes: 16 additions, 6 deletions.
> ------------------------------------------------------------
>
>
> diff --git a/www/roster/models/group.rb b/www/roster/models/group.rb
> index acc40e9..0015b1d 100644
> --- a/www/roster/models/group.rb
> +++ b/www/roster/models/group.rb
> @@ -8,16 +8,26 @@ def self.list
>      groups = ASF::Group.list.map(&:id)
>      groups -= ASF::Committee.list.map(&:id)
>      groups.map! {|group| [group, "LDAP group"]}
> -
>      # add services...
>      groups += ASF::Service.list.map {|service| [service, "LDAP service"]}
>
>      # add authorization (asf and pit)
> -    groups += ASF::Authorization.new('asf').to_h.
> -      map {|id, list| [id, "ASF Auth"]}
> -
> -    groups += ASF::Authorization.new('pit').to_h.
> -      map {|id, list| [id, "PIT Auth"]}
> +    begin
> +      groups += ASF::Authorization.new('asf').to_h.
> +        map {|id, list| [id, "ASF Auth"]}
> +    rescue # in case to_h does not work
> +      ASF::Authorization.new('asf').each do |id,list|
> +        groups += [[id, "ASF Auth"]]
> +      end
> +    end
> +    begin
> +      groups += ASF::Authorization.new('pit').to_h.
> +        map {|id, list| [id, "PIT Auth"]}
> +    rescue # in case to_h does not work
> +      ASF::Authorization.new('pit').each do |id,list|
> +        groups += [[id, "PIT Auth"]]
> +      end
> +    end
>
>      groups.sort
>    end