maxveldink / activerecord-ejection_seat Goto Github PK
View Code? Open in Web Editor NEWEject from an ActiveRecord model to a Sorbet T::Struct, or buckle back in.
License: MIT License
Eject from an ActiveRecord model to a Sorbet T::Struct, or buckle back in.
License: MIT License
The mechanics of this library are very similar to another serializer in sorbet-schema, where an AR model is formatting converting to and from. We can ship a serializer implementation here to allow this behavior using the sorbet-schema infrastructure.
When eject
is called on an instance of an ActiveRecord model that defines ejects_to
, Sorbet does not know the method exists. Further, we don't know what the return type should be, so we're forced to use the typed: false
sigil.
Tapioca allows for custom compilers to generate RBIs for a project based on given conditions. We should add one for ejection_seat
to give more type information.
Right now, we only support simple mappings onto T::Struct
. This is fine if you just need the id of a relation for a given model. What I'd love to do is have types like
module Types
class User < T::Struct
const :name, String
const :location, Location
end
class Location < T::Struct
const :name, String
end
end
and be able to eject
a user, look up the location information via the association and also eject the location onto this type.
Caveat - We need to be careful of circular requires here. Something will need to prevent trying to create infinite structs if two types reference each other. We should not create any associations if the type of that association is the ejection target of the receiver.
We should have the option between a Sorbet T::Struct and a Ruby 3.2 Data.define
type
Currently, when you add activerecord-ejection_seat
to your Gemfile
, it will auto-require the Ejectable
module in ActiveRecord::Base
to make it available to all models automatically. There probably should be an option for auto-requiring (current behavior) or manually requiring. This would allow a company to have an explicit extend Ejectable
in their ApplicationRecord
or only extend Ejectable
on the models they want to have that functionality for.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.