[ANN] Integrative - for integrating ActiveRecord models with external resources

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:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs