{"id":16381064,"url":"https://github.com/jasl/acts_as_priceable","last_synced_at":"2026-06-20T03:31:15.018Z","repository":{"id":12796777,"uuid":"15470569","full_name":"jasl/acts_as_priceable","owner":"jasl","description":"a easy way to store price as cents in database, but keep usability","archived":false,"fork":false,"pushed_at":"2013-12-27T18:43:28.000Z","size":116,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-05-30T17:31:00.206Z","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/jasl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-27T09:12:11.000Z","updated_at":"2013-12-27T18:43:28.000Z","dependencies_parsed_at":"2022-09-02T13:31:52.253Z","dependency_job_id":null,"html_url":"https://github.com/jasl/acts_as_priceable","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jasl/acts_as_priceable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasl%2Facts_as_priceable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasl%2Facts_as_priceable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasl%2Facts_as_priceable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasl%2Facts_as_priceable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jasl","download_url":"https://codeload.github.com/jasl/acts_as_priceable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasl%2Facts_as_priceable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34556494,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-20T02:00:06.407Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-10-11T03:53:17.981Z","updated_at":"2026-06-20T03:31:15.001Z","avatar_url":"https://github.com/jasl.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"ActsAsPriceable\n====\n\nA easy way to store price as cents in database, but keep usability. It designed for ActiveModel, not dependent Rails or\nActiveRecord.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'acts_as_priceable', github: 'jasl/acts_as_priceable'\n```\n\nAnd then execute:\n\n    $ bundle\n\n## Usage\n\nSay you have a model, `Llama`.  You can buy `Llama`s for a `cost`.  Let's add the `cost` to the `Llama` model.\n\nFirst, you need define a column named `cost_in_cents` for persistence, this is a convention,\nbut you can change it by `suffix` option.\n\nNow we just need to tell model that the `cost` field is act_as_priceable\n\n```ruby\n# app/models/llama.rb\n\nclass Llama \u003c ActiveRecord::Base\n  acts_as_priceable :cost\nend\n```\n\n**Important for Mongoid user: you need add `include ActsAsPriceable` in your model.**\n\nAnd now lets check it out in the console\n\n```ruby\n\u003e\u003e llama = Llama.last\n\u003e\u003e llama.cost # =\u003e nil\n\u003e\u003e llama.cost = 100\n\u003e\u003e llama.cost_in_cents # =\u003e 10000\n\u003e\u003e llama.cost # =\u003e 100\n```\n\nBy default, `cost` should be a `BigDecimal`,\nif you want to present price as other type like [Money](https://github.com/RubyMoney/money), can give `class` option.\n\nIsn't that special. So go, and add prices easily to your models, with ActsAsPriceable.\n\nPS: `acts_as_priceable` can take more than one field at a time, so go ahead and load it up like a baked potato.\n\n```ruby\nacts_as_priceable :retail_price, :employee_price, :cost\n```\n\nPS2: how it powerful\n```ruby\nacts_as_priceable :charge, initializer: -\u003e(price_in_cents) { Money.new (price_in_cents), 'CNY' }\n```\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Added some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n## License\n\nThis project rocks and uses MIT-LICENSE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasl%2Facts_as_priceable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjasl%2Facts_as_priceable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasl%2Facts_as_priceable/lists"}