{"id":13879107,"url":"https://github.com/drexed/lite-form","last_synced_at":"2025-07-20T04:33:11.972Z","repository":{"id":35111819,"uuid":"208136523","full_name":"drexed/lite-form","owner":"drexed","description":"Ruby Form based framework (aka form objects)","archived":false,"fork":false,"pushed_at":"2023-03-08T20:16:43.000Z","size":51,"stargazers_count":1,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-08T13:39:55.854Z","etag":null,"topics":["form-object","ruby"],"latest_commit_sha":null,"homepage":"https://drexed.github.io/lite-form","language":"Ruby","has_issues":false,"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/drexed.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-09-12T20:02:34.000Z","updated_at":"2021-07-22T20:19:13.000Z","dependencies_parsed_at":"2024-01-13T20:57:00.001Z","dependency_job_id":"b4b5f5d1-e8af-49b2-8777-28bdbf580261","html_url":"https://github.com/drexed/lite-form","commit_stats":{"total_commits":23,"total_committers":2,"mean_commits":11.5,"dds":0.04347826086956519,"last_synced_commit":"768d95035c18ad648fd644478e3d73b8c09e04f2"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/drexed/lite-form","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drexed%2Flite-form","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drexed%2Flite-form/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drexed%2Flite-form/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drexed%2Flite-form/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drexed","download_url":"https://codeload.github.com/drexed/lite-form/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drexed%2Flite-form/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266067271,"owners_count":23871324,"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":["form-object","ruby"],"created_at":"2024-08-06T08:02:10.079Z","updated_at":"2025-07-20T04:33:11.926Z","avatar_url":"https://github.com/drexed.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Lite::Form\n\n[![Gem Version](https://badge.fury.io/rb/lite-form.svg)](http://badge.fury.io/rb/lite-form)\n[![Build Status](https://travis-ci.org/drexed/lite-form.svg?branch=master)](https://travis-ci.org/drexed/lite-form)\n\nLite::Form is a library for using the form object pattern to separate business logic\nfrom model from classes.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'lite-form'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install lite-form\n\n## Table of Contents\n\n* [Setup](#setup)\n* [Usage](#usage)\n* [Forms](#forms)\n\n## Setup\n\n### Generators\n\nUse `rails g form NAME` will generate the following files:\n\n```erb\napp/forms/[name]_form.rb\n```\n\nIf a `ApplicationForm` file in the `app/forms` directory is available, the\ngenerator will create file that inherit from `ApplicationForm` if not it will\nfallback to `Lite::Form::Base`.\n\n### Forms\n\nYou will need to fill this class with the methods and actions you want to perform:\n\n```ruby\nclass UserForm \u003c ApplicationForm\n\n  # Setup up your form attributes using active model attributes\n  # or PORO attr_*\n  attribute :name, :string\n  attribute :age, :integer, default: 18\n\n  attr_accessor :signature\n\n  # Setup your form validations like you would on model objects\n  validates :name, presence: true\n\n  # Access 6 predefined callbacks to trigger before, after, and\n  # around your actions. Available callbacks are `initialize`\n  # `commit`, `create`, `rollback`, `save`, and `update`.\n  before_create :prepend_signature!\n  after_update :append_signature!\n\n  private\n\n  # Action methods are required methods that get executed when\n  # you call an active model persistence such as `create`,\n  # `save`, and `update`\n  def create_action\n    # Propagation methods help you perform an action on an object.\n    # If successful is returns the result else it adds the object\n    # errors to the form object. Available propagation methods are:\n    # `create_and_return!(object, params)`,\n    # `update_and_return!(object, params)`,\n    # `save_and_return!(object)`\n    create_and_return!(User, attributes)\n  end\n\n  def update_action\n    run_callbacks(:commit) do\n      ActiveRecord::Base.transaction do\n        user = User.find(attributes[:id])\n        update_and_return!(user, attributes.slice(:id))\n\n        # The `save_and_return!` supports on/off validation\n        user.settings.web_notification = true\n        save_and_return!(user.settings, validate: false)\n      end\n    end\n  rescue StandardError =\u003e e\n    # This will run the `rollback` callback and re-raise the error.\n    raise_transaction_rollback(e)\n  end\n\n  def prepend_signature!\n    self.signature = \"Prefix #{name}\"\n  end\n\n  def append_signature!\n    self.signature = \"#{signature} Suffix\"\n  end\n\nend\n```\n\n## Usage\n\nTo access the form you need to pass the object to the form class and thats it.\n\n```ruby\nform = UserForm.new(params)\nform.save #=\u003e UserForm object\n\n# - or -\n\nUserForm.create(params) #=\u003e UserForm object\n\n# - or -\n\nUserForm.perform(:update, params) do |result, success, failure|\n  success.call { redirect_to(user_path, notice: \"User can be found at: #{result}\") }\n  failure.call { redirect_to(root_path, notice: \"User cannot be found at: #{result}\") }\nend\n```\n\n## Forms\n\nThe following mixins are included for you in the form base file so you can use it to setup\nyour form in any way, shape and form. The forms `model_name` will tried to be inferred from\nthe form object name, if not it will default back to its class name. There are also 4 most\ncommon callbacks used with forms already setup to be used.\n\n``` ruby\n# Default mixins that are included\nextend ActiveModel::Callbacks\nextend ActiveModel::Naming\nextend ActiveModel::Translation\n\ninclude ActiveModel::Model\ninclude ActiveModel::Attributes\ninclude ActiveModel::Dirty\ninclude ActiveModel::Serialization\n\n# Default callbacks that are defined\ndefine_model_callbacks :initialize\ndefine_model_callbacks :commit\ndefine_model_callbacks :create\ndefine_model_callbacks :rollback\ndefine_model_callbacks :save\ndefine_model_callbacks :update\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 tags, 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/[USERNAME]/lite-form. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Lite::Form project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/lite-form/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrexed%2Flite-form","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrexed%2Flite-form","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrexed%2Flite-form/lists"}