{"id":24745838,"url":"https://github.com/vfsoraki/grimoire","last_synced_at":"2025-03-23T00:22:13.312Z","repository":{"id":195490363,"uuid":"436036289","full_name":"vfsoraki/grimoire","owner":"vfsoraki","description":"Supercharged Elixir structs","archived":false,"fork":false,"pushed_at":"2021-12-07T22:59:16.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-28T03:31:12.845Z","etag":null,"topics":["elixir","structs"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vfsoraki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-12-07T21:53:23.000Z","updated_at":"2021-12-07T22:59:20.000Z","dependencies_parsed_at":"2023-09-18T08:43:53.845Z","dependency_job_id":null,"html_url":"https://github.com/vfsoraki/grimoire","commit_stats":null,"previous_names":["vfsoraki/grimoire"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vfsoraki%2Fgrimoire","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vfsoraki%2Fgrimoire/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vfsoraki%2Fgrimoire/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vfsoraki%2Fgrimoire/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vfsoraki","download_url":"https://codeload.github.com/vfsoraki/grimoire/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245037447,"owners_count":20550872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","structs"],"created_at":"2025-01-28T03:29:54.269Z","updated_at":"2025-03-23T00:22:13.269Z","avatar_url":"https://github.com/vfsoraki.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Grimoire\n\nSuperchared structs!\n\nSay, there is this struct:\n\n```elixir\ndefmodule User do\n    defstruct [:first_name, :last_name]\nend\n```\n\nAnd you need a function `full_name` to concatenate `first_name` and `last_name`.\n\nYou can define a function somewhere like:\n\n```elixir\ndef full_name(user), do: \"#{user.first_name} #{user.last_name}\"\n```\n\nAnd use it:\n\n```elixir\n\"Welcome #{full_name(user)}!\"\n```\n\nOK, but we can do better.\n\n`Grimoire` allows you to define:\n\n```elixir\ndefmodule User do\n    import Grimoire\n\n    defstruct [:first_name, :last_name]\n\n    grimoire do\n        def full_name(user), do: \"#{user.first_name} #{user.last_name}\"\n    end\nend\n```\n\nAnd when you need `full_name`:\n\n```elixir\nimport Grimoire\n\n\"Welcome #{user~\u003efullname}!\"\n```\n\nYou can also define:\n\n```elixir\ngrimoire do\n    def full_name(user), do: \"#{user.first_name} #{user.last_name}\"\n    def full_name(user, :upcase), do: user |\u003e full_name() |\u003e String.upcase()\nend\n```\n\nAnd use:\n\n```elixir\nimport Grimoire\n\n\"Welcome #{user~\u003efull_name(:upcase)}!\"\n```\n\nBasically, `Grimoire` allows you to _attach_ some functions to your structs.\n\n`Ecto` schemas are structs too! You can supercharge them like any other struct:\n\n```elixir\ndefmodule User do\n    use Ecto.Schema\n    import Grimoire\n\n    schema \"users\" do\n        field :first_name, :string\n        field :last_name, :string\n    end\n\n    grimoire do\n        def full_name(user), do: \"#{user.first_name} #{user.last_name}\"\n        def full_name(user, :upcase), do: user |\u003e full_name() |\u003e String.upcase()\n    end\nend\n\n# Usage\nimport Grimoire\n\n\"Welcome #{user~\u003efull_name(:upcase)}!\"\n```\n\nYou can think of this as _computed fields_ too.\n\n\n## Installation\n\nThis package is not available in Hex, so you might want to add it from git.\nI plan to publish it on Hex soon.\n\n```elixir\n{:grimoire, git: \"https://github.com/vfsoraki/grimoire\"}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvfsoraki%2Fgrimoire","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvfsoraki%2Fgrimoire","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvfsoraki%2Fgrimoire/lists"}