Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

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

wants to merge 1 commit into from

Conversation

hypomodern
Copy link

...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 rspec/rspec-core#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 :).

…legating method_missing to Hash in the specific case.

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

jhwist commented Jan 9, 2013

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

@srikanthjeeva
Copy link

+1 .. break my build too.

@glennr
Copy link

glennr commented Feb 25, 2013

+1

1 similar comment
@rpcolom
Copy link

rpcolom commented Feb 26, 2013

+1

@glennr
Copy link

glennr commented Feb 27, 2013

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 

@prashantrajan
Copy link

+1

2 similar comments
@hirakiuc
Copy link

hirakiuc commented Aug 5, 2013

+1

@bwiggs
Copy link

bwiggs commented Nov 7, 2013

+1

@kidlab
Copy link

kidlab commented Dec 12, 2013

I got the same issue. +1

@mikegee
Copy link

mikegee commented Dec 23, 2013

+1 from me, too.

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

@Spone
Copy link

Spone commented Dec 30, 2013

+1 same issue here

@Drakula2k
Copy link

+1

1 similar comment
@heaven
Copy link

heaven commented Jan 17, 2014

👍

weilu added a commit to hpyhacking/peatio that referenced this pull request Mar 13, 2014
weilu added a commit to hpyhacking/peatio that referenced this pull request Mar 13, 2014
weilu added a commit to hpyhacking/peatio that referenced this pull request Mar 19, 2014
weilu added a commit to hpyhacking/peatio that referenced this pull request Mar 25, 2014
mguymon pushed a commit to mguymon/settingslogic that referenced this pull request May 8, 2014
@sld
Copy link

sld commented Jun 19, 2014

👍

1 similar comment
@cofiem
Copy link
Contributor

cofiem commented Jul 23, 2014

👍

gittmaan added a commit to gittmaan/settingslogic that referenced this pull request Mar 6, 2015
…ing)

Fix Array#flatten on an array containing a Settingslogic object
binarylogic#36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.