Formalism Model Forms
Ruby gem with standard Formalism forms for (Sequel) models. Used by Flame Generate Toys.
Installation
Add this line to your application's Gemfile:
gem 'formalism-model_forms'
And then execute:
bundle install
Or install it yourself as:
gem install formalism-model_forms
Usage
# forms/_base.rb
require 'formalism/model_forms'
## Define base form and model forms via gem
module MyProject
module Forms
## Base class for forms
class Base < Formalism::Form
end
end
Formalism::ModelForms.define_for_project self
end
.define_for_project
requires project namespace (self
in the example above)
and allows such options:
-
:forms_namespace
, default isproject_namespace::Forms
-
:models_namespace
, default isproject_namespace::Models
# forms/user/create.rb
module MyProject
module Forms
module User
class Create < Formalism::ModelForms::Create
field :name
private
def validate
errors.add 'Name is not provided' if name.to_s.empty?
end
# `execute` is inherited from `Formalism::ModelForms`
end
end
end
end
Development
After checking out the repo, run bundle install
to install dependencies.
Then, run toys rspec
to run the tests.
To install this gem onto your local machine, run toys gem install
.
To release a new version, run toys gem release %version%
.
See how it works here.
Contributing
Bug reports and pull requests are welcome on GitHub.
License
The gem is available as open source under the terms of the MIT License.