Ruby on Rails
Tuesday, July 12, 2016
As I couldn't find the library for working with external resources in Rails, I made this gem:
https://github.com/netizer/integrative
A long time ago I thought that that's what ActiveResource id for, but:
- There is no system of associations between ActiveResource models and ActiveRecord models
- ActiveResource has a lot of features related to modifying external resources, but I never found it particularly useful. Usually I just want to "enrich" my models with some content fetched from some (usually internal) REST API.
To make it more clear, what you can use it for, here's an example:
All feedback is welcome.
Krzysiek
-- https://github.com/netizer/integrative
A long time ago I thought that that's what ActiveResource id for, but:
- There is no system of associations between ActiveResource models and ActiveRecord models
- ActiveResource has a lot of features related to modifying external resources, but I never found it particularly useful. Usually I just want to "enrich" my models with some content fetched from some (usually internal) REST API.
To make it more clear, what you can use it for, here's an example:
class User < ApplicationRecord include Integrative::Integrator integrates :relation, requires: [:with] end class Relation include Integrative::Integrated def self.integrative_find(ids, integration) Friend.where(user_id: integration.call_options[:with].id, other_user_id: ids) end end
User.where(public: true).integrate(:relation, with: current_user).limit(1000)
The above code would fetch Friend models only once.
All feedback is welcome.
Krzysiek
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8e0a7056-873d-486d-8d71-51704abdaf12%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment