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

Multiple inheritence does not work correctly with relative operators #244

Closed
colinjneville opened this issue Jun 9, 2018 · 2 comments
Closed

Comments

@colinjneville
Copy link

When a layout makes a relative adjustment to a key that does not appear in the last layout specified in extends, the value for that key is left as the string value including the operator (e.g. '+= 100').
For example, the example in the documentation for multiple inheritence will fail because x is a string:

socrates:
  x: 100
plato:
  y: 200
aristotle:
  extends:
    - socrates
    - plato
  x: += 50    # evaluates to 250 from plato
require 'squib'

Squib::Deck.new(cards: 1, layout: 'test.yml') do
  circle radius: 50, layout: :aristotle
  
  save_png prefix: 'test_'
end
lib/ruby/2.4.0/forwardable.rb:229:in `arc': no implicit conversion to float from string (TypeError)

I'm new to Ruby, so I may be reading something wrong, but it looks like recurse_extends merges the current layout with each parent separately (so aristotle/socrates['x'] is 150, aristotle/plato['x'] is '+= 50'), then those are all merged with the later parents taking priority when multiple values exist for the same key. Since aristotle/plato['x'] technically has a value, it overwrites the expected value, so aristotle['x'] == '+= 50'.

@andymeneely
Copy link
Owner

Yeah you're right - I remember fixing this somewhere back along the way. Wonder what happened.

You can also see what the layout computes to with a puts layout in there. In this case it comes out to

{"socrates"=>{"x"=>100}, "plato"=>{"y"=>200}, "aristotle"=>{"extends"=>["socrates", "plato"], "x"=>"+= 50", "y"=>200}}

Good catch. Looking into it.

@andymeneely
Copy link
Owner

Turns out I never tested this case. I think I've handled it. The docs were also wrong, so I fixed that too. The new docs will be correct once I put out the new release. Expect this fix in v0.14.2

andymeneely added a commit that referenced this issue Jul 31, 2018
The case of using relative operators and multiple inheritance is handled now.

Fixes #244
andymeneely added a commit that referenced this issue Jul 31, 2018
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

No branches or pull requests

2 participants