joelmoss / delivered Goto Github PK
View Code? Open in Web Editor NEWSimple runtime type checking for Ruby method signatures
License: MIT License
Simple runtime type checking for Ruby method signatures
License: MIT License
Calling this...
confirm! off_session: true
on a method with this signature...
sig manual: T.Boolean, payment_method_id: T.Nilable(String)
Raises...
Delivered::ArgumentError: `Transaction::PaymentIntent#confirm!` expected `` as keyword arg :off_session, but received `true`
Type checking may not always be needed, for example you may not want it in production. A ENV var could be a good way to disable type checking globally.
Currently sig
uses a returns
keyword arg, which can obviously conflict. We can change it to one of the following, but not sure which… 🤔
sig [String, age: Integer] => User
or…
sig(String, age: Integer) { User }
... or both!
Hi! First of all I loved the idea so far, thanks for making it open source! I also thought of something like this but I never actually implemented it. Sorbet is a little bit heavy lift and RBS is too far from runtime to me, but this is a simple implementation. I even think it may be eventually be able to export to RBS for IDE support (an entirely different conversation, but wanted to mention it)
While trying it out i found out it does not have support for class methods. Here's an example on how to reproduce
require 'delivered'
class User
extend Delivered::Signature
sig String, age: Integer, returns: String
def initialize(name, age:)
"User #{name} created with age #{age}"
end
sig String, returns: String
def self.example(user)
123
end
end
User.example(1)
# should throw error because of the integer as parameter, and also because of the integer as returned value
I may be able to submit a PR for this in the short term, but wanted to submit the issue first, in case you or someone else wants to do it before
Right now a NoMatchingPatternError
exception is raised when a type does not match. This is great for us devs, but not so much for end users.
Hi! Curious if boolean types are supported in this implementation, and if so how it'll be done on the sig call
. Specifically asking because
Boolean type doesn't exist as such.
sig Boolean, returns: Boolean
def something(b)
!b
end
Some alternatives if that's not implemented, can be to create a class to be used as type like Sorbet or RBS does Types::Boolean
or Bool
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.