{"id":15432354,"url":"https://github.com/pragmarb/pragma-rails","last_synced_at":"2025-04-10T23:23:54.328Z","repository":{"id":56888637,"uuid":"73838837","full_name":"pragmarb/pragma-rails","owner":"pragmarb","description":"Ruby on Rails integration for the Pragma architecture.","archived":false,"fork":false,"pushed_at":"2018-08-12T11:24:11.000Z","size":141,"stargazers_count":6,"open_issues_count":5,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-24T20:11:35.402Z","etag":null,"topics":["api","ecosystem","pragma","ruby","ruby-on-rails","trailblazer"],"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/pragmarb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-11-15T17:34:39.000Z","updated_at":"2019-04-01T18:23:38.000Z","dependencies_parsed_at":"2022-08-20T23:40:45.681Z","dependency_job_id":null,"html_url":"https://github.com/pragmarb/pragma-rails","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pragmarb%2Fpragma-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pragmarb%2Fpragma-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pragmarb%2Fpragma-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pragmarb%2Fpragma-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pragmarb","download_url":"https://codeload.github.com/pragmarb/pragma-rails/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248111936,"owners_count":21049576,"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":["api","ecosystem","pragma","ruby","ruby-on-rails","trailblazer"],"created_at":"2024-10-01T18:26:12.988Z","updated_at":"2025-04-10T23:23:54.300Z","avatar_url":"https://github.com/pragmarb.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pragma on Rails\n\n[![Build Status](https://travis-ci.org/pragmarb/pragma-rails.svg?branch=master)](https://travis-ci.org/pragmarb/pragma-rails)\n[![Coverage Status](https://coveralls.io/repos/github/pragmarb/pragma-rails/badge.svg?branch=master)](https://coveralls.io/github/pragmarb/pragma-rails?branch=master)\n[![Maintainability](https://api.codeclimate.com/v1/badges/e51e8d7489eb72ab97ba/maintainability)](https://codeclimate.com/github/pragmarb/pragma-rails/maintainability)\n\nThis gem provides Ruby on Rails integration for the [Pragma](https://github.com/pragmarb/pragma) architecture.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'pragma-rails'\n```\n\nAnd then execute:\n\n```console\n$ bundle\n```\n\nOr install it yourself as:\n\n```console\n$ gem install pragma-rails\n```\n\n## Usage\n\n### Generators\n\nThis gem provides a `pragma:resource` generator for creating a new resource with the default CRUD\noperations:\n\n```console\n$ rails g pragma:resource image\n      create  app/resources/api/v1/image\n      create  app/resources/api/v1/image/contract/base.rb\n      create  app/resources/api/v1/image/contract/create.rb\n      create  app/resources/api/v1/image/contract/update.rb\n      create  app/resources/api/v1/image/decorator/instance.rb\n      create  app/resources/api/v1/image/decorator/collection.rb\n      create  app/resources/api/v1/image/operation/create.rb\n      create  app/resources/api/v1/image/operation/destroy.rb\n      create  app/resources/api/v1/image/operation/index.rb\n      create  app/resources/api/v1/image/operation/show.rb\n      create  app/resources/api/v1/image/operation/update.rb\n      create  app/resources/api/v1/image/policy.rb\n      create  app/controllers/api/v1/images_controller.rb\n      create  spec/requests/api/v1/images_spec.rb\n       route  namespace :api do\n    namespace :v1 do\n      resources :images, only: %i(index show create update destroy)\n    end\n  end\n```\n\nYou can also specify an API version (the default is 1):\n\n```console\n$ rails g pragma:resource image -v 2\n      create  app/resources/api/v2/image\n      create  app/resources/api/v2/image/contract/base.rb\n      create  app/resources/api/v2/image/contract/create.rb\n      create  app/resources/api/v2/image/contract/update.rb\n      create  app/resources/api/v2/image/decorator.rb\n      create  app/resources/api/v2/image/operation/create.rb\n      create  app/resources/api/v2/image/operation/destroy.rb\n      create  app/resources/api/v2/image/operation/index.rb\n      create  app/resources/api/v2/image/operation/show.rb\n      create  app/resources/api/v2/image/operation/update.rb\n      create  app/resources/api/v2/image/policy.rb\n      create  app/controllers/api/v2/images_controller.rb\n      create  spec/requests/api/v2/images_spec.rb\n       route  namespace :api do\n    namespace :v2 do\n      resources :images, only: %i(index show create update destroy)\n    end\n  end\n\n```\n\n### Controllers\n\n`Pragma::Rails::Controller` gives your controller the ability to run Pragma operations:\n\n```ruby\nmodule API\n  module V1\n    class ArticlesController \u003c ApplicationController\n      include Pragma::Rails::Controller\n\n      def create\n        run API::V1::Article::Operation::Create\n      end\n    end\n  end\nend\n```\n\nIn the example above, `ArticlesController#create` will run the `API::V1::Article::Operation::Create`\noperation and respond with the status code, headers and resource returned by the operation.\n\nBy default, the `#params` method will be used as the operation's parameters and `#current_user`, if\navailable, will be used as the operation's user. You can override these defaults by overriding the\n`#operation_params` and `#operation_user` methods in your controller:\n\n```ruby\nmodule API\n  module V1\n    class ArticlesController \u003c ApplicationController\n      include Pragma::Rails::Controller\n\n      def create\n        run API::V1::Article::Operation::Create\n      end\n\n      private\n\n      def operation_params\n        params.merge(my_additional: 'param')\n      end\n\n      def operation_user\n        User.authenticate_from params\n      end\n    end\n  end\nend\n```\n\nYou may also define `#policy_context` to [pass additional context](https://github.com/pragmarb/pragma-policy#passing-additional-context) \nto your policies.\n\n### Resource Controllers\n\nResource controllers (provided by the `Pragma::Rails::ResourceController` module) abstract even more \nof the logic behind your controllers by inferring the operations supported by a resource and \nautomatically providing controller actions that run them.\n\nWith a resource controller, the example above could be rewritten as:\n\n```ruby\nmodule API\n  module V1\n    class ArticlesController \u003c ApplicationController\n      include Pragma::Rails::ResourceController\n\n      private\n\n      def operation_params\n        params.merge(my_additional: 'param')\n      end\n\n      def operation_user\n        User.authenticate_from params\n      end\n    end\n  end\nend\n```\n\nYou will still have to define a route to your `#create` action, of course, but you don't have to\nwrite the action anymore!\n\nThis works with any actions, not only the default CRUD actions defined by Rails. So, for instance, \nif you have an `API::V1::Article::Operation::Publish` operation, a `#publish` action will be \naccessible in the `API::V1::ArticlesController` controller.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/pragmarb/pragma-rails.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpragmarb%2Fpragma-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpragmarb%2Fpragma-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpragmarb%2Fpragma-rails/lists"}