Title: Restrict method arguments by model getters · Issue #99 · onyxframework/sql · GitHub
Open Graph Title: Restrict method arguments by model getters · Issue #99 · onyxframework/sql
X Title: Restrict method arguments by model getters · Issue #99 · onyxframework/sql
Description: Just an idea. module Onyx::SQL macro restrict(t, model, &block) {% for exp in block.body.expressions %} {% unless exp.is_a?(Call) && exp.name == "getter" %} {% raise "Must be getter" %} {% end %} {% found = false %} {% for method in t.me...
Open Graph Description: Just an idea. module Onyx::SQL macro restrict(t, model, &block) {% for exp in block.body.expressions %} {% unless exp.is_a?(Call) && exp.name == "getter" %} {% raise "Must be getter" %} {% end %} {...
X Description: Just an idea. module Onyx::SQL macro restrict(t, model, &block) {% for exp in block.body.expressions %} {% unless exp.is_a?(Call) && exp.name == "getter" %} {% raise "Mus...
Opengraph URL: https://github.com/onyxframework/sql/issues/99
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Restrict method arguments by model getters","articleBody":"Just an idea.\r\n\r\n```crystal\r\nmodule Onyx::SQL\r\n macro restrict(t, model, \u0026block)\r\n {% for exp in block.body.expressions %}\r\n {% unless exp.is_a?(Call) \u0026\u0026 exp.name == \"getter\" %}\r\n {% raise \"Must be getter\" %}\r\n {% end %}\r\n\r\n {% found = false %}\r\n\r\n {% for method in t.methods %}\r\n {% if method.name == exp.args.first.var \u0026\u0026\r\n method.return_type == exp.args.first.type %}\r\n {% found = true %}\r\n {% end %}\r\n {% end %}\r\n\r\n {% raise \"#{model} is restricted to have `#{exp.args.first.var}` getter with return type `#{exp.args.first.type}`\" unless found %}\r\n {% end %}\r\n end\r\nend\r\n\r\nclass User\r\n property id : Int32?\r\n property name : String?\r\n\r\n def initialize(@id = nil, @name = nil)\r\n end\r\nend\r\n\r\ndef foo(user : T) forall T\r\n Onyx::SQL.restrict({{T}}, User) do\r\n getter id : Int32\r\n getter name : String?\r\n end\r\n\r\n pp user\r\nend\r\n\r\nrecord UserObject, id : Int32, name : String?\r\n\r\n# foo(UserObject.new(42, nil)) # OK\r\nfoo(User.new(42, nil)) # User is restricted to have `id` getter with return type `Int32`\r\n```","author":{"url":"https://github.com/vladfaust","@type":"Person","name":"vladfaust"},"datePublished":"2019-05-04T08:15:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/99/sql/issues/99"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:25495d82-e392-ddea-8358-c88363a69642 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A7F0:39F7A9:272310E:3212358:69801E11 |
| html-safe-nonce | 122f0b565c403b05d459cef7e1d12c15116f2d3c40d6a4a789e5e8d5f7539705 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBN0YwOjM5RjdBOToyNzIzMTBFOjMyMTIzNTg6Njk4MDFFMTEiLCJ2aXNpdG9yX2lkIjoiNzE3NTk5MjEwMzkyNTcxODU0NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c6745b2ad1b329aa7348af12c3f3420fa39c0d6e352132bad33d5f17e144b5da |
| hovercard-subject-tag | issue:440298423 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/onyxframework/sql/99/issue_layout |
| twitter:image | https://opengraph.githubassets.com/69b1782ea1e5e934e8c56a9e4b3cd4c08493a92e2ea11b4280506bcb4f07179a/onyxframework/sql/issues/99 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/69b1782ea1e5e934e8c56a9e4b3cd4c08493a92e2ea11b4280506bcb4f07179a/onyxframework/sql/issues/99 |
| og:image:alt | Just an idea. module Onyx::SQL macro restrict(t, model, &block) {% for exp in block.body.expressions %} {% unless exp.is_a?(Call) && exp.name == "getter" %} {% raise "Must be getter" %} {% end %} {... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | vladfaust |
| hostname | github.com |
| expected-hostname | github.com |
| None | 60279d4097367e16897439d16d6bbe4180663db828c666eeed2656988ffe59f6 |
| turbo-cache-control | no-preview |
| go-import | github.com/onyxframework/sql git https://github.com/onyxframework/sql.git |
| octolytics-dimension-user_id | 43681765 |
| octolytics-dimension-user_login | onyxframework |
| octolytics-dimension-repository_id | 104816583 |
| octolytics-dimension-repository_nwo | onyxframework/sql |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 104816583 |
| octolytics-dimension-repository_network_root_nwo | onyxframework/sql |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7c85641c598ad130c74f7bcc27f58575cac69551 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width