{"id":16102365,"url":"https://github.com/sshaw/alias2","last_synced_at":"2025-04-06T01:11:47.933Z","repository":{"id":59150522,"uuid":"173495485","full_name":"sshaw/alias2","owner":"sshaw","description":"Make classes, modules, and constants accessible via a different namespace.","archived":false,"fork":false,"pushed_at":"2019-05-02T05:10:30.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-27T00:41:00.572Z","etag":null,"topics":["alias","aliasing","metaprogramming","namespaces","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/sshaw.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}},"created_at":"2019-03-02T20:27:27.000Z","updated_at":"2019-05-05T17:31:26.000Z","dependencies_parsed_at":"2022-09-13T08:42:18.401Z","dependency_job_id":null,"html_url":"https://github.com/sshaw/alias2","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Falias2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Falias2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Falias2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Falias2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sshaw","download_url":"https://codeload.github.com/sshaw/alias2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247419871,"owners_count":20936013,"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":["alias","aliasing","metaprogramming","namespaces","ruby"],"created_at":"2024-10-09T18:53:39.908Z","updated_at":"2025-04-06T01:11:47.911Z","avatar_url":"https://github.com/sshaw.png","language":"Ruby","readme":"# alias2\n\nMake classes, modules, and constants accessible via a different namespace.\n\n[![Build Status](https://travis-ci.org/sshaw/alias2.svg?branch=master)](https://travis-ci.org/sshaw/alias2)\n\n## Usage\n\n```rb\nrequire \"alias2\"\nrequire \"some/very/long/name/here\" # If not already loaded (or autoloaded)\n```\n\nAn `Array` of constant names to alias can be provided:\n```rb\nalias2 Some::Very::Long::Name::Here, %w[Foo Bar Baz]\n```\n\nThis is the same as:\n```rb\nFoo = Some::Very::Long::Name::Here::Foo\nBar = Some::Very::Long::Name::Here::Bar\nBaz = Some::Very::Long::Name::Here::Baz\n```\n\nThe namespace can also be a `String`.\n\nTo alias everything in the namespace to the top-level:\n```rb\nalias2 Some::Very::Long::Name::Here, \"*\"\n```\n\nSame as above:\n```rb\nFoo = Some::Very::Long::Name::Here::Foo\nBar = Some::Very::Long::Name::Here::Bar\nBaz = Some::Very::Long::Name::Here::Baz\n```\n\nIf you'd like to alias them using a different name you can:\n```rb\nalias2 Some::Very::Long::Name::Here, :Foo =\u003e \"FooHoo\", :Bar =\u003e \"BarHar\", :Baz =\u003e \"Bazzzz\"\n```\n\nSame as:\n```rb\nFooHoo = Some::Very::Long::Name::Here::Foo\nBarHar = Some::Very::Long::Name::Here::Bar\nBazzzz = Some::Very::Long::Name::Here::Baz\n```\n\nKeys can also be `String`s.\n\nYou can filter the classes/modules to alias. Here, only subclasses of `ActiveRecord::Base` will be aliased:\n```rb\nalias2 Some::Very::Long::Name::Here, \"*\" do |klass|\n  klass \u003c ActiveRecord::Base\nend\n```\n\nThe above is the same as:\n```rb\nFoo = Some::Very::Long::Name::Here::Foo if Some::Very::Long::Name::Here::Foo.is_a?(ActiveRecord::Base)\nBar = Some::Very::Long::Name::Here::Bar if Some::Very::Long::Name::Here::Bar.is_a?(ActiveRecord::Base)\nBaz = Some::Very::Long::Name::Here::Baz if Some::Very::Long::Name::Here::Baz.is_a?(ActiveRecord::Base)\n```\n\nWhen a block is given you can omit the alias. It will default to `\"*\"`.\n\nThe block can also return an alias:\n```rb\nalias2 Some::Very::Long::Name::Here do |klass|\n  klass.name.end_with?(\"Foo\") ? \"Foo_X\" : klass.name.split(\"::\")[-1]\nend\n```\n\nThis is the same as:\n```rb\nFoo_X = Some::Very::Long::Name::Here::Foo if Some::Very::Long::Name::Here::Foo.name.end_with?(\"Foo\")\nBar = Some::Very::Long::Name::Here::Bar\nBaz = Some::Very::Long::Name::Here::Baz\n```\n\nAn alias' target can also be a namespace you want created:\n```rb\nalias2 Some::Very::Long::Name::Here, :Foo =\u003e \"New::Namespace::SameFoo\", :Bar =\u003e \"BarHar\"\n```\n\nSame as:\n```rb\nmodule New\n  module Namespace\n    SameFoo = Some::Very::Long::Name::Here::Foo\n  end\nend\n\nBarHar = Some::Very::Long::Name::Here::Bar\n```\n\nOr it can be an existing namespace:\n```rb\nalias2 Some::Very::Long::Name::Here, :Foo =\u003e \"Existing::Namespace::Foo\", :Bar =\u003e \"BarHar\"\n```\n\nSame as:\n```rb\nExisting::Namespace::Foo = Some::Very::Long::Name::Here::Foo\nBarHar = Some::Very::Long::Name::Here::Bar\n```\n\nIn all cases the original namespace is not modified and remains in scope.\n\n### Errors\n\n- `NameError` - raised when a constant cannot be found or when a constant is already defined\n- `ArgumentError` - raised when an alias list or block is not provided\n\n## See Also\n\n* [aliased](https://metacpan.org/pod/aliased) - The Perl module that served as inspiration\n* [require3](https://github.com/sshaw/require3) - `Kernel#require` something and make it accessible via a different namespace\n* [class2](https://github.com/sshaw/class2) - Easily create hierarchies that support nested attributes, type conversion, serialization and more\n\n## Author\n\nSkye Shaw [skye.shaw AT gmail]\n\n## License\n\nReleased under the MIT License: http://www.opensource.org/licenses/MIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsshaw%2Falias2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsshaw%2Falias2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsshaw%2Falias2/lists"}