settingslogic icon indicating copy to clipboard operation
settingslogic copied to clipboard

Fix Array#flatten on an array containing a Settingslogic object...

Open hypomodern opened this issue 13 years ago • 15 comments

...by delegating method_missing to Hash in the specific case.

On newer rubies, Array#flatten calls #to_ary on everything in the array, which raises a MissingSetting error from a Settingslogic object. This was reported as an rspec-core issue, but is more a ruby/settingslogic deal.

At any rate, you'd see an unhandled Settingslogic::MissingSetting: Missing setting 'to_ary' if you happened to have a Settingslogic object in an array that got flattened.

This is particularly a pain point with newer rspec. See https://github.com/rspec/rspec-core/issues/620 for the initial bug report, which was referred to Settingslogic for a fix. I concur.

My editor hates trailing whitespace, so that's redacted in there too :).

hypomodern avatar Aug 15 '12 17:08 hypomodern

I'm +1 for this as it currently bites me.

jhwist avatar Jan 09 '13 13:01 jhwist

+1 .. break my build too.

srikanthjeeva avatar Jan 18 '13 08:01 srikanthjeeva

+1

glennr avatar Feb 25 '13 12:02 glennr

+1

rpcolom avatar Feb 26 '13 12:02 rpcolom

Interestingly, after monkey-patching this I got

/usr/local/opt/rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/settingslogic-2.0.8/lib/settingslogic.rb:173:in missing_key': Missing setting 'to_str' in /Users/glennr/git/blah/config/models/debit_order_rejection_settings.yml (Settingslogic::MissingSetting) from /Users/glennr/git/blah/spec/support/settingslogic_rspec1_hack.rb:14:inmethod_missing' from /usr/local/opt/rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/settingslogic-2.0.8/lib/settingslogic.rb:77:in method_missing' from /usr/local/opt/rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rspec-1.3.1/lib/spec/example/example_group_hierarchy.rb:49:injoin'

So I ended up adding

super if name === :to_str # delegate to Hash

ie.

class Settingslogic < Hash                                                                                             

  def method_missing(name, *args, &block)                                                                              
    super if name === :to_ary # delegate to Hash                                                                       
    super if name === :to_str # delegate to Hash                                                                       
    key = name.to_s                                                                                                    
    return missing_key("Missing setting '#{key}' in #{@section}") unless has_key? key                                  
    value = fetch(key)                                                                                                 
    create_accessor_for(key)                                                                                           
    value.is_a?(Hash) ? self.class.new(value, "'#{key}' section in #{@section}") : value                               
  end                                                                                                                  

end 

glennr avatar Feb 27 '13 14:02 glennr

+1

prashantrajan avatar Apr 30 '13 05:04 prashantrajan

+1

hirakiuc avatar Aug 05 '13 08:08 hirakiuc

+1

bwiggs avatar Nov 07 '13 16:11 bwiggs

I got the same issue. +1

kidlab avatar Dec 12 '13 05:12 kidlab

+1 from me, too.

Is there anything we can do to help get this merged?

mikegee avatar Dec 23 '13 13:12 mikegee

+1 same issue here

Spone avatar Dec 30 '13 23:12 Spone

+1

Drakula2k avatar Jan 17 '14 14:01 Drakula2k

:+1:

heaven avatar Jan 17 '14 14:01 heaven

:+1:

sld avatar Jun 19 '14 06:06 sld

:+1:

cofiem avatar Jul 23 '14 05:07 cofiem