Comments (6)
Sorry, this issue didn't come through via email - I found it by accident!
Yes, this is documented in CHANGES and I also blogged about it (uhm.... probably).
As you already guessed, the "problem" is uber, which now handles all the dynamic options (like if: lambda { .. }
. This breaking change was deliberate. Apologies for the breakage, though, but I had to cleanse the options - now they're all executed with the same mechanism.
You can fix that by ignoring the args, as in
if: lambda { |*| beers? }
Your suggestion to check arity is clever, however I decided not to do that a while ago as it adds complexity and still doesn't catch all the gotchas.
Is the |*|
OK for you?
from representable.
My 5 cents - I'd allow blocks that have no parameters because I think that having to capture them when you don't need them just adds noise. I prefer handling that problem even if it adds complexity rather than let clients of uber/representative have to handle it. In that case I'd either handle the arity mismatch if possible or take the opportunity to fail in a more friendly way in order to make it easier for people to troubleshoot. It's also a breaking change (as we found out) - I'm not sure if you're following semantic versioning but I'd expect the major version to bump with a change like this.
These are just suggestions though, we've already worked around it as you suggested :)
from representable.
Hmm, yeah, a simple arity == 0
would actually do the trick. You're probably right, I might add it to uber.
I totally see your point on being "user-friendly" - however, this is a double-edged sword. Some projects completely went the wrong way in the last decade, providing "user-friendliness" to a degree where the internal magic, guessing and complexity outweighs the code use.
It's a pain in the ass to get rid of that madness now by deprecating all former forms. I don't want that in my gems and often explicit code is better understandable than magic methods that expose different APIs.
I try to but don't follow semantic versioning because I would be releasing a major version every two weeks. Most of my changes don't break existing code, though!
About semantic versioning: From my experience I can tell you that there should either be a fourth level (1.2.3.4), where 1.2 to 1.3 means internal (correction: semi-public) API has changed, or people should accept major number like 14.1.0. It is impossible to follow semantic versioning if your gem is going an aggressively innovative path.
from representable.
Here's the line from uber that executes the :if
block: https://github.com/apotonick/uber/blob/master/lib/uber/options.rb#L77 It's so beautiful without any if..else
from representable.
Also, you could update the readme, under available options and conditions. Adding |*|
really isn't a problem, but finding out what needs to be done was for me.
from representable.
Thanks @jan - that's what pull requests are for
from representable.
Related Issues (20)
- Dynamically choosing representer for STI HOT 1
- Inheriting a base representer HOT 1
- Error while starting server with Rails 5.2.0.rc1 HOT 7
- Using the :skip_parse option with JSON::Hash values produces Pipeline::Stop HOT 1
- XML Encoding? HOT 3
- Populator docs or examples? HOT 4
- XML namespaces
- Options hash passed to setter has incorrect value for collection properties
- Collection parsing raises an error if the value is nil HOT 4
- Document nested inherit: true
- Parsing null values results in property being set despite `reader` property present
- parsing array of arrays
- Bug in dependency package declarative-option update HOT 1
- Nested keys within hash are getting mutated HOT 5
- Custom writer: method is not invoked or not invoked correctly HOT 2
- Can't activate multi_json on (>= 1.14.1), already activated multi_json-1.11.3 HOT 3
- Representable doesn't work as expected on truffleruby-21.3.0 HOT 1
- Nokogiri deprecation warning
- `nested` tries to assign to non-existent property when parsing nil body HOT 7
- Combining nested include/exclude with regular include/exclude HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from representable.