{"id":17257001,"url":"https://github.com/waterlink/aop","last_synced_at":"2025-04-14T06:11:06.626Z","repository":{"id":26184323,"uuid":"29630166","full_name":"waterlink/aop","owner":"waterlink","description":"Very thin AOP gem for Ruby","archived":false,"fork":false,"pushed_at":"2015-05-22T16:28:35.000Z","size":316,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-23T23:55:37.228Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/waterlink.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}},"created_at":"2015-01-21T23:56:07.000Z","updated_at":"2017-02-08T02:22:34.000Z","dependencies_parsed_at":"2022-08-06T08:16:02.853Z","dependency_job_id":null,"html_url":"https://github.com/waterlink/aop","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waterlink%2Faop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waterlink%2Faop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waterlink%2Faop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waterlink%2Faop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/waterlink","download_url":"https://codeload.github.com/waterlink/aop/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248830395,"owners_count":21168272,"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":[],"created_at":"2024-10-15T07:16:06.882Z","updated_at":"2025-04-14T06:11:06.604Z","avatar_url":"https://github.com/waterlink.png","language":"Ruby","readme":"# Aop\n\n[![Build Status](https://travis-ci.org/waterlink/aop.svg?branch=master)](https://travis-ci.org/waterlink/aop)\n\nVery thin AOP gem for Ruby.\n\nThin and fast framework for Aspect Oriented Programming in Ruby.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'aop'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install aop\n\n## Usage\n\n### Before advice\n\n```ruby\nmodule Authentication\n  Aop[\"BankAccount#transfer:before\"].advice do |account, *args, \u0026blk|\n    can!(:transfer, account)\n  end\n\n  def self.can!(action, subject)\n    # raises error if current user can't execute `action` on `subject`\n  end\nend\n```\n\n### After advice\n\n```ruby\nmodule Analytics\n  Aop[\"User#sign_in:after\"].advice do |target, *args, \u0026blk|\n    report(\"sign_in\", user.id)\n  end\nend\n```\n\n### Around advice\n\n```ruby\nmodule Transactional\n  Aop[\"BankAccount#transfer:around\"].advice do |joint_point, account, *args, \u0026blk|\n    start_transaction\n    joint_point.call\n    finish_transaction\n  end\nend\n```\n\n### Class methods\n\nUse `.method` notation:\n\n```ruby\nmodule Transactional\n  Aop[\"BankAccount.transfer:around\"].advice do |joint_point, klass, *args, \u0026blk|\n    start_transaction\n    joint_point.call\n    finish_transaction\n  end\nend\n```\n\n### Multiple classes, methods and advices\n\nUse `,` to use multiple classes, methods and advices:\n\n```ruby\nmodule Analytics\n  Aop[\"User,Admin#sign_in,.sign_up,#sign_out:before,:after\"].advice do |target, *args, \u0026blk|\n    report(\"auth_action\", user.id)\n  end\nend\n```\n\n### Handling missed pointcuts\n\nWhen pointcut is gone, for example when method or class gets renamed, it is a potential bug, because some code will not be run. This library tackles this problem by failing hard when pointcut can not be found.\n\nExample:\n\n```ruby\nAop[\"Admin#sign_in:after\"].advice do |target, *args, \u0026blk|\n  # .. do something ..\nend\n```\n\nThen somebody renames `Admin#sign_in` to `Admin#logout`, and when you run the code you will get:\n\n```\nAop::PointcutNotFound: Unable to find pointcut Admin#sign_in\n    Reason: #\u003cNameError: undefined method `sign_in' for class `Admin'\u003e\n    .. backtrace ..\n```\n\n## Contributing\n\n1. Fork it ( https://github.com/waterlink/aop/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaterlink%2Faop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwaterlink%2Faop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaterlink%2Faop/lists"}