{"id":14956017,"url":"https://github.com/johansenja/sparkl","last_synced_at":"2026-01-21T01:01:59.820Z","repository":{"id":58365025,"uuid":"531435388","full_name":"johansenja/sparkl","owner":"johansenja","description":"A decorator-like way of writing hooks for your Rails controllers","archived":false,"fork":false,"pushed_at":"2022-09-01T08:49:33.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-06T17:08:37.639Z","etag":null,"topics":["decorators","decorators-python","rails","ruby","ruby-gem","ruby-on-rails"],"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/johansenja.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":"2022-09-01T08:46:22.000Z","updated_at":"2022-09-07T16:03:13.000Z","dependencies_parsed_at":"2022-09-04T14:21:38.544Z","dependency_job_id":null,"html_url":"https://github.com/johansenja/sparkl","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/johansenja/sparkl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johansenja%2Fsparkl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johansenja%2Fsparkl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johansenja%2Fsparkl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johansenja%2Fsparkl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johansenja","download_url":"https://codeload.github.com/johansenja/sparkl/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johansenja%2Fsparkl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28620572,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T23:49:58.628Z","status":"ssl_error","status_checked_at":"2026-01-20T23:47:29.996Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["decorators","decorators-python","rails","ruby","ruby-gem","ruby-on-rails"],"created_at":"2024-09-24T13:12:11.207Z","updated_at":"2026-01-21T01:01:59.620Z","avatar_url":"https://github.com/johansenja.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sparkl\n\nSparkl provides a decorator-like way of writing hooks for your Rails controllers. Example:\n\n```ruby\nclass MyController \u003c ApplicationController\n  extend Sparkl::Decoration\n\n  def_decorator :special_auth, before_action: [:auth, if: -\u003e { true or false }]\n\n  special_auth def show\n    # ... normal controller logic here\n  end\n\n  # instead of:\n  # before_action :auth, only: [:show], if: -\u003e { true or false }\nend\n```\n\nDecorators can also be chained:\n\n```ruby\nclass MyController \u003c ApplicationController\n  extend Sparkl::Decoration\n\n  def_decorator :no_auth, skip_before_action: :authorize\n  def_decorator :verify_scope, after_action: -\u003e() {\n    # ... logic to check policy scoping...\n  }\n\n  verify_scope no_auth def show\n    # ... normal controller logic here\n  end\n\n  # or with parentheses:\n  # verify_scope(\n  #   no_auth(\n  #     def show\n  #       # ... normal controller logic here\n  #     end\n  #   )\n  # )\nend\n```\n\nand can also be reused:\n\n```ruby\nmodule MyActions\n  extend Sparkl::Decorator\n\n  def_decorator :redirect_if_true, before_action: [ :handle_redirect, { if: -\u003e{ true } } ]\n\n  private def handle_redirect\n    redirect_to \"...\"\n  end\nend\n\nclass MyController \u003c ApplicationController\n  extend MyActions\n\n  redirect_if_true def index\n    # ...\n  end\nend\n```\n\n`def_decorator` is also aliased as `decorator`.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'sparkl'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install sparkl\n\n## Usage\n\nSee above for examples.\n\nIn the decorator definition, you define the moment the action will be performed - it can be\nperformed at multiple times if you like:\n\n```ruby\ndecorator :foo, before_action: -\u003e{ puts 'foo' }, after_action: -\u003e{ puts :bar }\n```\n\nAvailable timings mirror Rails' own options:\n\n```\nbefore_action\nprepend_before_action\nafter_action\nprepend_after_action\nskip_before_action\nskip_after_action\n```\n\nEach action can take any of the arguments that a normal rails action would:\n\n```ruby\ndecorator :foo, before_action: [:do_foo, if: :condition?]\n\n# ...\n\n# need to have do_foo and condition? methods defined\ndef do_foo\n  # ...\nend\n\ndef condition?\n  true\nend\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/johansenja/sparkl.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohansenja%2Fsparkl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohansenja%2Fsparkl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohansenja%2Fsparkl/lists"}