{"id":18510780,"url":"https://github.com/envato/encapsulate_as_money","last_synced_at":"2025-04-09T04:33:23.849Z","repository":{"id":16006237,"uuid":"18749616","full_name":"envato/encapsulate_as_money","owner":"envato","description":"Surprise me ;)","archived":false,"fork":false,"pushed_at":"2021-01-24T23:45:57.000Z","size":42,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":73,"default_branch":"master","last_synced_at":"2024-04-24T10:18:06.845Z","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/envato.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":"2014-04-14T05:39:04.000Z","updated_at":"2024-04-06T18:50:32.000Z","dependencies_parsed_at":"2022-08-30T11:20:18.790Z","dependency_job_id":null,"html_url":"https://github.com/envato/encapsulate_as_money","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Fencapsulate_as_money","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Fencapsulate_as_money/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Fencapsulate_as_money/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Fencapsulate_as_money/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/envato","download_url":"https://codeload.github.com/envato/encapsulate_as_money/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247980833,"owners_count":21027803,"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-11-06T15:25:06.961Z","updated_at":"2025-04-09T04:33:23.313Z","avatar_url":"https://github.com/envato.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EncapsulateAsMoney\n\n[![License MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/envato/encapsulate_as_money/blob/master/LICENSE.txt)\n[![Gem Version](https://img.shields.io/gem/v/encapsulate_as_money.svg?maxAge=2592000)](https://rubygems.org/gems/encapsulate_as_money)\n[![Gem Downloads](https://img.shields.io/gem/dt/encapsulate_as_money.svg?maxAge=2592000)](https://rubygems.org/gems/encapsulate_as_money)\n[![Build Status](https://github.com/envato/encapsulate_as_money/workflows/tests/badge.svg?branch=master)](https://github.com/envato/encapsulate_as_money/actions?query=branch%3Amaster+workflow%3Atests)\n\nWant your model attribute to be a [Money](https://github.com/RubyMoney/money)\ninstance? EncapsulateAsMoney provides a simple way to get this done!\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'encapsulate_as_money'\n\nAnd then execute:\n\n    $ bundle\n\n## Usage\n\n### Rails\n\nAdd the `encapsulate_as_money` method to the Active Record base class.\n\n```ruby\nActiveRecord::Base.extend(EncapsulateAsMoney)\n```\n\nNow say you have the model:\n\n```ruby\nclass MyModel \u003c ActiveRecord::Base\n  encapsulate_as_money :amount\nend\n```\n\nWhich is based on the database table:\n\n```ruby\ncreate_table \"my_models\" do |table|\n  table.integer \"amount\"\nend\n```\n\nNow we can create and save an instance like:\n\n```ruby\nMyModel.create!(amount: 5.dollars)\n```\n\nThis will create a row as such:\n\n| id | amount |\n| --:| ------:|\n|  1 |    500 |\n\nNote the value is represented as cents.\n\nOnce persisted we can find the value like:\n\n```ruby\nMyModel.find_by_id(1).amount #=\u003e 5.dollars\n```\n\nNote that it uses the default Money currency.\n\n## Contributing\n\n1. Fork it ( https://github.com/envato/encapsulate_as_money/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%2Fenvato%2Fencapsulate_as_money","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenvato%2Fencapsulate_as_money","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenvato%2Fencapsulate_as_money/lists"}