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

Conflict with ActiveSupport delegate ? #6

Closed
samqiu opened this issue Jan 31, 2014 · 7 comments
Closed

Conflict with ActiveSupport delegate ? #6

samqiu opened this issue Jan 31, 2014 · 7 comments
Labels

Comments

@samqiu
Copy link

samqiu commented Jan 31, 2014

Hi @karmi

Here is my Article model with delegate defined.

Seems conflict with Elasticsearch::Model::Support::Forwardable

Model example

class Article << ActiveRecord::Base
  include Elasticsearch::Model
  include Elasticsearch::Model::Callbacks

  delegate(:content, to: :cover_letter, prefix: true)

end

Trace

11:40:37 sidekiq.1 | wrong number of arguments (2 for 1)
11:40:37 sidekiq.1 | /Users/sam/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/forwardable.rb:225:in `single_delegate'
11:40:37 sidekiq.1 | /Users/sam/web/tulip/app/models/article.rb:224:in `<class:Article>'
11:40:37 sidekiq.1 | /Users/sam/web/tulip/app/models/article.rb:31:in `<top (required)>'
11:40:37 sidekiq.1 | /Users/sam/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:469:in `load'
...
11:40:37 sidekiq.1 | /Users/sam/.rvm/gems/ruby-2.0.0-p353/bin/sidekiq:23:in `<main>'

Thanks!

@karmi
Copy link
Contributor

karmi commented Jan 31, 2014

Yes, definitely seems like it. I'll look into it, it'll take some time, though. Couple of notes:

a) The implementation is quite isolated in support/forwardable.rb, so it should be easy to tweak it.

b) I couldn't decide whether to use ActiveSupport's delegation or not, in the end it would make more sense, I guess.

c) The implementation shouldn't trample on the delegate method in your class, that's some unfortunate side-effect of using Forwardable from Ruby's standard library, I think. That should be fixed.

@zzet
Copy link

zzet commented Feb 10, 2014

Actual for me too :(

@snop-snov
Copy link

And for me

@karmi
Copy link
Contributor

karmi commented Feb 14, 2014

Looking into it... ripped out stdlib's Forwardable, replaced with #delegate, though there's a problem with ActiveRecord 3:

Due to inspect in https://github.com/rails/rails/blob/8dec2e7281a1b38db037dc23becd1a147d1fcae1/activesupport/lib/active_support/core_ext/module/delegation.rb#L179 I'm getting "Connection not established errors:.

gems/activerecord-3.2.16/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection': ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished)
  from .../gems/1.9.1/gems/activerecord-3.2.16/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
  from .../gems/1.9.1/gems/activerecord-3.2.16/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
  from .../gems/1.9.1/gems/activerecord-3.2.16/lib/active_record/model_schema.rb:224:in `table_exists?'
  from .../gems/1.9.1/gems/activerecord-3.2.16/lib/active_record/base.rb:423:in `inspect'
  from .../gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/core_ext/module/delegation.rb:137:in `to_s'
  from .../gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/core_ext/module/delegation.rb:137:in `block in delegate'
  from .../gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/core_ext/module/delegation.rb:125:in `each'
  from .../gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/core_ext/module/delegation.rb:125:in `delegate'
  from .../elasticsearch-rails/elasticsearch-model/lib/elasticsearch/model.rb:105:in `singletonclass'
  from .../elasticsearch-rails/elasticsearch-model/lib/elasticsearch/model.rb:104:in `block in included'
  from .../elasticsearch-rails/elasticsearch-model/lib/elasticsearch/model.rb:79:in `class_eval'
  from .../elasticsearch-rails/elasticsearch-model/lib/elasticsearch/model.rb:79:in `included'

karmi added a commit that referenced this issue Feb 14, 2014
@karmi karmi closed this as completed in df9e70c Feb 14, 2014
@karmi
Copy link
Contributor

karmi commented Feb 14, 2014

Replaced Forwardable by ActiveSupport's delegate, should be all set now.

Had to monkeypatch ActiveRecord::Base.inspect on ActiveRecord < 4 to prevent errors mentioned above.

@zzet
Copy link

zzet commented Feb 14, 2014

@karmi 👍

@samqiu
Copy link
Author

samqiu commented Feb 18, 2014

Cool! @karmi

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

No branches or pull requests

4 participants