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

Reimplement proxy code of ElementProxy to be less severe #127

Open
dtognazzini opened this issue May 27, 2015 · 2 comments
Open

Reimplement proxy code of ElementProxy to be less severe #127

dtognazzini opened this issue May 27, 2015 · 2 comments
Milestone

Comments

@dtognazzini
Copy link
Contributor

ElementProxy undefs a bunch of standard methods on objects:

# Remove all instance methods so even things like class()
# get handled by method_missing(). <lifted from activerecord>
instance_methods.each do |m|
  unless m.to_s =~ /^(?:nil\?|send|object_id|to_a|tap)$|^__|^respond_to/
    undef_method m
  end
end

This undefing is too severe and can cause issues when methods common to most objects are not available. #123 describes an issue with RSpec expectations. Additionally, inspecting instances of ElementProxy in debuggers like Rubymine can sometimes crash the debugger.

Reimplement the proxy code in ElementProxy to be less severe.

Some ideas:

  1. Use SimpleDelegator.
  2. Don't undef any methods.
@dtognazzini
Copy link
Contributor Author

Another idea here would be to collapse the ElementProxy behavior into Element whereby the internal node attribute would function as the "implicit_element" of ElementProxy.

This would mean that callers would get references to instances of Element subclasses, making is_a? checks easier, but also changing the contract of methods generated by the element DSL.

It's unclear if this change would require a major version bump.

@jacob-carlborg
Copy link
Contributor

It's unclear if this change would require a major version bump.

Technically removing ElementProxy is a breaking change, which would require a majort version bump. Although, I'm not sure if it was possible to know that ElementProxy actually existed, without looking in the source code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants