{"id":16382448,"url":"https://github.com/andyobtiva/easily_typable","last_synced_at":"2026-03-05T23:15:48.549Z","repository":{"id":482076,"uuid":"107735","full_name":"AndyObtiva/easily_typable","owner":"AndyObtiva","description":"Ruby module that facilitates English-like type checking in an inheritance hierarchy via \"type_name?\" methods","archived":false,"fork":false,"pushed_at":"2023-04-12T05:19:46.000Z","size":50,"stargazers_count":1,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-22T18:52:50.852Z","etag":null,"topics":["mixin","rails","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AndyObtiva.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2009-01-15T02:32:14.000Z","updated_at":"2020-06-30T10:56:06.000Z","dependencies_parsed_at":"2023-07-05T15:02:55.053Z","dependency_job_id":null,"html_url":"https://github.com/AndyObtiva/easily_typable","commit_stats":{"total_commits":49,"total_committers":3,"mean_commits":"16.333333333333332","dds":"0.061224489795918324","last_synced_commit":"04f9fe069b18cf0bf1d08d36084cf9f9a3b6e21c"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/AndyObtiva/easily_typable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndyObtiva%2Feasily_typable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndyObtiva%2Feasily_typable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndyObtiva%2Feasily_typable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndyObtiva%2Feasily_typable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AndyObtiva","download_url":"https://codeload.github.com/AndyObtiva/easily_typable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndyObtiva%2Feasily_typable/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265837583,"owners_count":23836557,"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":["mixin","rails","ruby"],"created_at":"2024-10-11T04:05:25.313Z","updated_at":"2026-03-05T23:15:48.492Z","avatar_url":"https://github.com/AndyObtiva.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EasilyTypable v1.0.2\n[![Gem Version](https://badge.fury.io/rb/easily_typable.svg)](http://badge.fury.io/rb/easily_typable)\n[![Build Status](https://api.travis-ci.org/AndyObtiva/easily_typable.svg?branch=master)](https://travis-ci.org/AndyObtiva/easily_typable)\n[![Coverage Status](https://coveralls.io/repos/github/AndyObtiva/easily_typable/badge.svg?branch=master)](https://coveralls.io/github/AndyObtiva/easily_typable?branch=master)\n[![Code Climate](https://codeclimate.com/github/AndyObtiva/easily_typable.svg)](https://codeclimate.com/github/AndyObtiva/easily_typable)\n\n## Introduction:\n\nAlthough polymorphism is a recommended standard in Object-Oriented programming\nfor invoking varied behavior in an inheritance hierarchy, sometimes it is still\nuseful to verify if a particular model belongs to a certain type when the\nbehavior concerned does not belong to the model and is too small to require a\nDesign Pattern like Strategy.\n\nA common example in Rails is checking user roles before rendering certain\nparts of the view:\n\n```erb\n\u003c% if user.is_a?(Admin) %\u003e\n  \u003c%= link_to 'Admin', admin_dashboard_path %\u003e\n\u003c% end %\u003e\n\u003c% if user.is_a?(Customer) %\u003e\n  \u003c%= link_to 'Customer Profile', customer_profile_path %\u003e\n\u003c% end %\u003e\n```\n\nTo avoid the `model.is_a?(Admin)` syntax, a more readable approach\nthat developers resort to is to add an English-like DSL method that hides the\ndetails of Object-Oriented type checking: `model.admin?`.\n\nThe Rails example above would then become:\n\n```erb\n\u003c% if user.admin? %\u003e\n  \u003c%= link_to 'Admin', admin_dashboard_path %\u003e\n\u003c% end %\u003e\n\u003c% if user.customer? %\u003e\n  \u003c%= link_to 'Customer Profile', customer_profile_path %\u003e\n\u003c% end %\u003e\n```\n\nImplementing such methods manually gets repetitive and error-prone, so an easier\nway to get these methods automatically is to mixin the ```EasilyTypable```\nmodule.\n\n## Example:\n\n```ruby\nrequire 'easily_typable' # in IRB at cloned project directory, call this instead: require './lib/easily_typable' \n\nclass Vehicle\n  include EasilyTypable\nend\n\nclass Car \u003c Vehicle\nend\n\nclass Truck \u003c Vehicle\nend\n\nclass Van \u003c Vehicle\nend\n\n\nputs Car.new.vehicle? # prints true\nputs Car.new.car? # prints true\nputs Car.new.truck? # prints false\nputs Car.new.van? # prints false\n\nputs Truck.new.vehicle? # prints true\nputs Truck.new.car? # prints false\nputs Truck.new.truck? # prints true\nputs Truck.new.van? # prints false\n\nputs Van.new.vehicle? # prints true\nputs Van.new.car? # prints false\nputs Van.new.truck? # prints false\nputs Van.new.van? # prints true\n```\n\n## Release Notes\n\n * v1.0.2: Support namespaced subclasses\n * v1.0.1: Rails model lazy loading now loads EasilyTypable methods automagically\n * v1.0.0: Initial EasilyTypable implementation for Ruby\n \n## Contributing to EasilyTypable\n\n * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.\n * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.\n * Fork the project.\n * Start a feature/bugfix branch.\n * Commit and push until you are happy with your contribution.\n * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.\n * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.\n\n## Copyright\n\n * Copyright (c) 2009-2020 Andy Maleh\n * See LICENSE.txt for further details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandyobtiva%2Feasily_typable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandyobtiva%2Feasily_typable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandyobtiva%2Feasily_typable/lists"}