{"id":15562131,"url":"https://github.com/mrkamel/attachie","last_synced_at":"2025-03-29T04:44:04.252Z","repository":{"id":48232400,"uuid":"203400850","full_name":"mrkamel/attachie","owner":"mrkamel","description":"Declarative and flexible attachments","archived":false,"fork":false,"pushed_at":"2023-09-04T06:52:51.000Z","size":69,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-03T14:36:18.283Z","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/mrkamel.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-20T15:11:33.000Z","updated_at":"2022-10-07T11:20:21.000Z","dependencies_parsed_at":"2024-12-09T03:22:38.644Z","dependency_job_id":null,"html_url":"https://github.com/mrkamel/attachie","commit_stats":{"total_commits":74,"total_committers":3,"mean_commits":"24.666666666666668","dds":0.3648648648648649,"last_synced_commit":"54ae80c53b65450bbe70e23e72eb33da8a686eda"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrkamel%2Fattachie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrkamel%2Fattachie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrkamel%2Fattachie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrkamel%2Fattachie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrkamel","download_url":"https://codeload.github.com/mrkamel/attachie/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246140542,"owners_count":20729797,"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-02T16:11:54.994Z","updated_at":"2025-03-29T04:44:04.229Z","avatar_url":"https://github.com/mrkamel.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Attachie\n\nDeclarative and flexible attachments.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'attachie'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install attachie\n\n## Usage\n\nFirst, `include Attachie` and specify an attachment:\n\n```ruby\nclass User\n  include Attachie\n\n  attachment :avatar, versions: {\n    icon: { path: \"users/:id/avatar/icon.jpg\" },\n    thumbnail: { path: \"users/:id/avatar/thumbnail.jpg\" },\n    original: { path: \"users/:id/avatar/original.jpg\" }\n  }\nend\n```\n\nPlease note, Attachie will interpolate colon prefixed segments like `:id` by\nreplacing it with the return value of the respective method.\n\nSecond, store blobs for your version:\n\n```ruby\nuser.avatar(:icon).store(\"blob\")\nuser.avatar(:thumbnail).store(\"blob\")\nuser.avatar(:original).store(\"blob\")\n```\n\nor via multipart upload\n\n```ruby\nuser.avatar(:icon).store_multipart do |upload|\n  upload.upload_part \"chunk1\"\n  upload.upload_part \"chunk2\"\n  # ...\nend\n```\n\nThird, add the images url to your views:\n\n```\nimage_tag user.avatar(:thumbnail).url\n```\n\nMore methods to manipulate the blobs:\n\n```ruby\nuser.avatar(:icon).delete\nuser.avatar(:icon).exists?\nuser.avatar(:icon).value\nuser.avatar(:icon).temp_url(expires_in: 2.days) # Must be supported by the driver\nuser.avator(:icon).download(\"/path/to/destination\")\n```\n\n## Drivers\n\nThe `Attachie` gem ships with the following drivers:\n\n* `Attachie::FileDriver`: To store files on the local file system\n* `Attachie::FakeDriver`: To store files in memory (for testing)\n* `Attachie::S3Driver`: To store files on S3\n\n### FileDriver\n\nTo use the file driver:\n\n```ruby\nrequire \"attachie/file_driver\"\n\nAttachie.default_options[:driver] = Attachie::FileDriver.new(\"/path/to/attachments\")\n\nclass User\n  include Attachie\n\n  attachment :avatar, host: \"www.example.com\", versions: {\n    # ...\n  }\nend\n```\n\n### S3Driver\n\nTo use the s3 driver:\n\n```ruby\nrequire \"attachie/s3_driver\"\n\nAttachie.default_options[:driver] = Attachie::S3Driver.new(Aws::S3::Client.new('...'))\n```\n\n### FakeDriver\n\nTo use the fake driver (useful for testing):\n\n```ruby\nrequire \"attachie/fake_driver\"\n\nAttachie.default_options[:driver] = Attache::FakeDriver.new\n```\n\nDrivers and other options can be set on an attachment level as well:\n\n```ruby\nclass User\n  include Attachie\n\n  attachment :avatar, driver: MyFileDriver, versions: {\n    # ...\n  }\nend\n```\n\n## Direct S3 Uploads\n\nAttachie allows to presign s3 post requests like:\n\n```ruby\nuser.avatar(:icon).presign_post(content_type: 'image/jpeg', ...)\n# =\u003e {\"fields\"=\u003e{\"key\"=\u003e\"path/to/object\",\"x-amz-signature\"=\u003e\"...\"},\"headers\":{},\"method\"=\u003e\"post\",\"url\"=\u003e\"...\"}\n```\n\n## Contributing\n\n1. Fork it ( https://github.com/mrkamel/attachie/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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrkamel%2Fattachie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrkamel%2Fattachie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrkamel%2Fattachie/lists"}