yaaf 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 897bfdef28cdce5ee405763d213d28c7b2e011a661c4a7106f52100786110f6d
4
- data.tar.gz: 3bd98b7cc8a9fcd78e982844a311ea56b7dd1dacbebc0d8c3c0d5f879a1c13fd
3
+ metadata.gz: f78d26d774f33785958812a5d3d449b5aa882c297f07e19436410d01bfb5157a
4
+ data.tar.gz: cfaa5d69b5041de56aad4b8b32059dff8512fdf0931165f2260320abc6d7ec53
5
5
  SHA512:
6
- metadata.gz: f073c7fa7d30bd7bfdafd4169dedc1af11cb4ad186c22f25237011cd23a7f19e628c1d5a6ac33d4b2318456800398a65e039a0cc8d74b517194c3852716b545c
7
- data.tar.gz: 94851b76f07a37e0c8f339e9e76e3a0576fadd0797ce0b5c53ddf307b9650016728e6ac99efb8adfcb1cf9857c0c14b851e66627159b7c1c36c3720887c1a0c1
6
+ metadata.gz: 05a43329b36959802bd0b1f81fc6d5d039a4090cd7fbba5d7fca5cf8b6e2c93779270fbe3ead65246367f22e5d23b917d8776a9e8e8859f40c2ed4d468c9ce35
7
+ data.tar.gz: 0cbfcbf3253f87f190364da712a9fda48f4354263a419d6c01ce571897454f27b8b8e0c616f04e7a0534ede4a5525d1d6c0bf590f18b2ec2db06556ad29d3f2f
data/README.md CHANGED
@@ -1,16 +1,17 @@
1
- # YAAF
2
-
3
- ![CI](https://github.com/rootstrap/yaaf/workflows/CI/badge.svg)
4
- [![Maintainability](https://api.codeclimate.com/v1/badges/c3dea064e1003b700260/maintainability)](https://codeclimate.com/github/rootstrap/yaaf/maintainability)
5
- [![Test Coverage](https://api.codeclimate.com/v1/badges/c3dea064e1003b700260/test_coverage)](https://codeclimate.com/github/rootstrap/yaaf/test_coverage)
1
+ ![YAAF](docs/images/logo.png)
6
2
 
7
3
  YAAF (Yet Another Active Form) is a gem that let you create form objects in an easy and Rails friendly way. It makes use of `ActiveRecord` and `ActiveModel` features in order to provide you with a form object that behaves pretty much like a Rails model, and still be completely configurable.
8
4
 
9
5
  We were going to name this gem `ActiveForm` to follow Rails naming conventions but given there are a lot of form object gems named like that we preferred to go with `YAAF`.
10
6
 
7
+ ![CI](https://github.com/rootstrap/yaaf/workflows/CI/badge.svg)
8
+ [![Maintainability](https://api.codeclimate.com/v1/badges/c3dea064e1003b700260/maintainability)](https://codeclimate.com/github/rootstrap/yaaf/maintainability)
9
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/c3dea064e1003b700260/test_coverage)](https://codeclimate.com/github/rootstrap/yaaf/test_coverage)
10
+
11
11
  ## Table of Contents
12
12
 
13
13
  - [Motivation](#motivation)
14
+ - [Why YAAF?](#why-yaaf)
14
15
  - [Installation](#installation)
15
16
  - [Usage](#usage)
16
17
  - [Setting up a form object](#setting-up-a-form-object)
@@ -47,6 +48,22 @@ For this reason we decided to build our own Form Object implementation. After se
47
48
 
48
49
  If you want to learn more about Form Objects you can check out [these great articles](#links).
49
50
 
51
+ ### Why YAAF?
52
+
53
+ - It is [64 lines long](https://github.com/rootstrap/yaaf/blob/master/lib/yaaf/form.rb#L64). As you can imagine, we did no magic in such a few lines of code, we just leveraged Rails modules in order to provide our form objects with a Rails-like behavior. You can review the code, it's easy to understand.
54
+
55
+ - It provides a similar API to `ActiveModel` models so you can treat them interchangeably.
56
+
57
+ - You can customize it 100%. We encourage you to have your own `ApplicationForm` which inherits from `YAAF::Form` and make the customizations you'd like for your app.
58
+
59
+ - It helps decoupling the frontend from the database. This is particularly important when using Rails as a JSON API with a frontend in React/Ember/Vue/Angular/you name it. If you were to use `accepts_nested_attributes_for` your frontend would need to know your database structure in order to build the request. With `YAAF` you can provide a the interface you think it's best.
60
+
61
+ - It easily supports nested models, collection of models and associated models. You have full control on their creation.
62
+
63
+ - It helps you keep your models, views and controllers thin by providing a better place where to put business logic. In the end, this will improve the quality of your codebase and make it easier to maintain and extend.
64
+
65
+ - It is an abstraction from production code. It has been working well for us, I'm confident it will work well for you too :)
66
+
50
67
  ## Installation
51
68
 
52
69
  Add this line to your application's Gemfile:
@@ -246,6 +263,7 @@ You can find a sample app making use of the gem [here](https://yaaf-examples.her
246
263
  - [Validating Form Objects](https://revs.runtime-revolution.com/validating-form-objects-8058fefc7b89)
247
264
  - [Disciplined Rails: Form Object Techniques & Patterns — Part 1](https://medium.com/@jaryl/disciplined-rails-form-object-techniques-patterns-part-1-23cfffcaf429)
248
265
  - [Complex form objects with Rails](https://www.codementor.io/@victor_hazbun/complex-form-objects-in-rails-qval6b8kt)
266
+ - [How to keep your controllers thin with form objects](https://ducktypelabs.com/how-to-keep-your-controllers-thin-with-form-objects)
249
267
 
250
268
  ## Development
251
269
 
@@ -269,4 +287,4 @@ Everyone interacting in the YAAF project's codebases, issue trackers, chat rooms
269
287
 
270
288
  YAAF is maintained by [Rootstrap](http://www.rootstrap.com) with the help of our [contributors](https://github.com/rootstrap/yaaf/contributors).
271
289
 
272
- [<img src="https://s3-us-west-1.amazonaws.com/rootstrap.com/img/rs.png" width="100"/>](http://www.rootstrap.com)
290
+ [![YAAF](docs/images/footer.png)](http://www.rootstrap.com)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module YAAF
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaaf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Manuel Ramallo
8
8
  - Santiago Bartesaghi
9
9
  autorequire:
10
- bindir: exe
10
+ bindir: bin
11
11
  cert_chain: []
12
- date: 2020-04-07 00:00:00.000000000 Z
12
+ date: 2020-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -156,26 +156,11 @@ executables: []
156
156
  extensions: []
157
157
  extra_rdoc_files: []
158
158
  files:
159
- - ".github/workflows/ci.yml"
160
- - ".gitignore"
161
- - ".reek.yml"
162
- - ".rspec"
163
- - ".rubocop.yml"
164
- - ".ruby-version"
165
- - CODE_OF_CONDUCT.md
166
- - CONTRIBUTING.md
167
- - Gemfile
168
159
  - LICENSE.txt
169
160
  - README.md
170
- - Rakefile
171
- - bin/console
172
- - bin/setup
173
- - docs/README.md
174
- - docs/recipes/simple_form.md
175
161
  - lib/yaaf.rb
176
162
  - lib/yaaf/form.rb
177
163
  - lib/yaaf/version.rb
178
- - yaaf.gemspec
179
164
  homepage: https://github.com/rootstrap/yaaf
180
165
  licenses:
181
166
  - MIT
@@ -197,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
182
  - !ruby/object:Gem::Version
198
183
  version: '0'
199
184
  requirements: []
200
- rubygems_version: 3.0.3
185
+ rubygems_version: 3.1.0.pre2
201
186
  signing_key:
202
187
  specification_version: 4
203
188
  summary: Easing the form object pattern in Rails applications.
@@ -1,42 +0,0 @@
1
- name: CI
2
-
3
- on: [push]
4
-
5
- jobs:
6
- build:
7
- if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')"
8
- runs-on: ubuntu-latest
9
- strategy:
10
- matrix:
11
- gemfile: [rails_4.0.0.gemfile, rails_5.0.0.gemfile, rails_5.2.3.gemfile, rails_6.0.0.gemfile, rails_master.gemfile]
12
- ruby_version: [2.4.x, 2.5.x, 2.6.x, 2.7.x]
13
- exclude:
14
- - gemfile: rails_master.gemfile
15
- ruby_version: 2.4.x
16
- - gemfile: rails_6.0.0.gemfile
17
- ruby_version: 2.4.x
18
- steps:
19
- - uses: actions/checkout@v2
20
- - name: Setup Ruby
21
- uses: actions/setup-ruby@v1
22
- with:
23
- ruby-version: ${{ matrix.ruby_version }}
24
- - name: Update rubygems when testing with Ruby 2.4.x
25
- if: startsWith(matrix.ruby_version, '2.4')
26
- run: |
27
- gem update --system --no-document
28
- - name: Before build
29
- run: |
30
- sudo apt-get install libsqlite3-dev
31
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
32
- chmod +x ./cc-test-reporter
33
- ./cc-test-reporter before-build
34
- env:
35
- CC_TEST_REPORTER_ID: aff2c7b9e07e54d5fc9e5588d2e2a8bab4f69950d35000edc2b6250bbaba477d
36
- - name: Build and test with Rake
37
- run: |
38
- gem install bundler:1.17.3
39
- bundle _1.17.3_ update
40
- bundle _1.17.3_ install --gemfile spec/gemfiles/${{ matrix.gemfile }} --jobs 4 --retry 3
41
- bundle _1.17.3_ exec rake code_analysis
42
- bundle _1.17.3_ exec rspec
data/.gitignore DELETED
@@ -1,14 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
12
-
13
- Gemfile.lock
14
- .irb_history
data/.reek.yml DELETED
@@ -1,128 +0,0 @@
1
- detectors:
2
- Attribute:
3
- enabled: false
4
- exclude: []
5
- BooleanParameter:
6
- enabled: true
7
- exclude: []
8
- ClassVariable:
9
- enabled: false
10
- exclude: []
11
- ControlParameter:
12
- enabled: true
13
- exclude: []
14
- DataClump:
15
- enabled: true
16
- exclude: []
17
- max_copies: 2
18
- min_clump_size: 2
19
- DuplicateMethodCall:
20
- enabled: true
21
- exclude: []
22
- max_calls: 1
23
- allow_calls: []
24
- FeatureEnvy:
25
- enabled: true
26
- exclude: []
27
- InstanceVariableAssumption:
28
- enabled: false
29
- IrresponsibleModule:
30
- enabled: false
31
- exclude: []
32
- LongParameterList:
33
- enabled: true
34
- exclude: []
35
- max_params: 4
36
- overrides:
37
- initialize:
38
- max_params: 5
39
- LongYieldList:
40
- enabled: true
41
- exclude: []
42
- max_params: 3
43
- ManualDispatch:
44
- enabled: true
45
- exclude: []
46
- MissingSafeMethod:
47
- enabled: false
48
- exclude: []
49
- ModuleInitialize:
50
- enabled: true
51
- exclude: []
52
- NestedIterators:
53
- enabled: true
54
- exclude: []
55
- max_allowed_nesting: 2
56
- ignore_iterators: []
57
- NilCheck:
58
- enabled: false
59
- exclude: []
60
- RepeatedConditional:
61
- enabled: true
62
- exclude: []
63
- max_ifs: 3
64
- SubclassedFromCoreClass:
65
- enabled: true
66
- exclude: []
67
- TooManyConstants:
68
- enabled: true
69
- exclude: []
70
- max_constants: 5
71
- TooManyInstanceVariables:
72
- enabled: true
73
- exclude: []
74
- max_instance_variables: 9
75
- TooManyMethods:
76
- enabled: true
77
- exclude: []
78
- max_methods: 25
79
- TooManyStatements:
80
- enabled: true
81
- exclude:
82
- - initialize
83
- max_statements: 12
84
- UncommunicativeMethodName:
85
- enabled: true
86
- exclude: []
87
- reject:
88
- - "/^[a-z]$/"
89
- - "/[0-9]$/"
90
- - "/[A-Z]/"
91
- accept: []
92
- UncommunicativeModuleName:
93
- enabled: true
94
- exclude: []
95
- reject:
96
- - "/^.$/"
97
- - "/[0-9]$/"
98
- accept:
99
- - Inline::C
100
- - "/V[0-9]/"
101
- UncommunicativeParameterName:
102
- enabled: true
103
- exclude: []
104
- reject:
105
- - "/^.$/"
106
- - "/[0-9]$/"
107
- - "/[A-Z]/"
108
- accept: []
109
- UncommunicativeVariableName:
110
- enabled: true
111
- exclude:
112
- - YAAF::Form#save_in_transaction
113
- reject:
114
- - "/^.$/"
115
- - "/[0-9]$/"
116
- - "/[A-Z]/"
117
- accept:
118
- - _
119
- UnusedParameters:
120
- enabled: true
121
- exclude: []
122
- UnusedPrivateMethod:
123
- enabled: false
124
- UtilityFunction:
125
- enabled: false
126
-
127
- exclude_paths:
128
- - config
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --format documentation
2
- --color
3
- --order rand
4
- --require spec_helper
@@ -1,85 +0,0 @@
1
- Layout/LineLength:
2
- Max: 100
3
- # To make it possible to copy or click on URIs in the code, we allow lines
4
- # containing a URI to be longer than Max.
5
- AllowURI: true
6
- URISchemes:
7
- - http
8
- - https
9
-
10
- Layout/SpaceBeforeFirstArg:
11
- Exclude:
12
-
13
- Lint/AmbiguousBlockAssociation:
14
- Exclude:
15
- - spec/**/*
16
-
17
- Lint/RescueException:
18
- Exclude:
19
- - lib/yaaf/form.rb
20
-
21
- Metrics/AbcSize:
22
- # The ABC size is a calculated magnitude, so this number can be an Integer or
23
- # a Float.
24
- Max: 15
25
-
26
- Metrics/BlockLength:
27
- CountComments: false # count full line comments?
28
- Max: 25
29
- Exclude:
30
- - 'yaaf.gemspec'
31
- - config/**/*
32
- - spec/**/*
33
- ExcludedMethods:
34
- - class_methods
35
-
36
- Metrics/BlockNesting:
37
- Max: 4
38
-
39
- Metrics/ClassLength:
40
- CountComments: false # count full line comments?
41
- Max: 200
42
-
43
- # Avoid complex methods.
44
- Metrics/CyclomaticComplexity:
45
- Max: 7
46
-
47
- Metrics/MethodLength:
48
- CountComments: false # count full line comments?
49
- Max: 24
50
-
51
- Metrics/ModuleLength:
52
- CountComments: false # count full line comments?
53
- Max: 200
54
-
55
- Metrics/ParameterLists:
56
- Max: 5
57
- CountKeywordArgs: true
58
-
59
- Metrics/PerceivedComplexity:
60
- Max: 12
61
-
62
- Style/Documentation:
63
- Enabled: false
64
-
65
- Style/FrozenStringLiteralComment:
66
- Enabled: false
67
-
68
- Style/HashEachMethods:
69
- Enabled: true
70
-
71
- Style/HashTransformKeys:
72
- Enabled: true
73
-
74
- Style/HashTransformValues:
75
- Enabled: true
76
-
77
- Style/ModuleFunction:
78
- Enabled: false
79
-
80
- Style/RescueModifier:
81
- Exclude:
82
- - spec/**/*
83
-
84
- Naming/PredicateName:
85
- Enabled: false
@@ -1 +0,0 @@
1
- 2.7.0
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at juan.ramallo[at]rootstrap.com or santiago.bartesaghi[at]rootstrap.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [https://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: https://contributor-covenant.org
74
- [version]: https://contributor-covenant.org/version/1/4/
@@ -1,42 +0,0 @@
1
- ## Contributing ##
2
-
3
- You can contribute to this repo if you have an issue, found a bug or think there's some functionality required that would add value to the gem. To do so, please check if there's not already an [issue](https://github.com/rootstrap/yaaf/issues) for that, if you find there's not, create a new one with as much detail as possible.
4
-
5
- If you want to contribute with code as well, please follow the next steps:
6
-
7
- 1. Read, understand and agree to our [code of conduct](https://github.com/rootstrap/yaaf/blob/master/CODE_OF_CONDUCT.md)
8
- 2. [Fork the repo](https://help.github.com/articles/about-forks/)
9
- 3. Clone the project into your machine:
10
- `$ git clone git@github.com:rootstrap/yaaf.git`
11
- 4. Access the repo:
12
- `$ cd yaaf`
13
- 5. Create your feature/bugfix branch:
14
- `$ git checkout -b your_new_feature`
15
- or
16
- `$ git checkout -b fix/your_fix` in case of a bug fix
17
- (if your PR is to address an existing issue, it would be good to name the branch after the issue, for example: if you are trying to solve issue 182, then a good idea for the branch name would be `182_your_new_feature`)
18
- 6. Write tests for your changes (feature/bug)
19
- 7. Code your (feature/bugfix)
20
- 8. Run the code analysis tool by doing:
21
- `$ rake code_analysis`
22
- 9. Run the tests:
23
- `$ bundle exec rspec`
24
- All tests must pass. If all tests (both code analysis and rspec) do pass, then you are ready to go to the next step:
25
- 10. Commit your changes:
26
- `$ git commit -m 'Your feature or bugfix title'`
27
- 11. Push to the branch `$ git push origin your_new_feature`
28
- 12. Create a new [pull request](https://help.github.com/articles/creating-a-pull-request/)
29
-
30
- Some helpful guides that will help you know how we work:
31
- 1. [Code review](https://github.com/rootstrap/tech-guides/tree/master/code-review)
32
- 2. [GIT workflow](https://github.com/rootstrap/tech-guides/tree/master/git)
33
- 3. [Ruby style guide](https://github.com/rootstrap/tech-guides/tree/master/ruby)
34
- 4. [Rails style guide](https://github.com/rootstrap/tech-guides/blob/master/ruby/rails.md)
35
- 5. [RSpec style guide](https://github.com/rootstrap/tech-guides/blob/master/ruby/rspec/README.md)
36
-
37
- For more information or guides like the ones mentioned above, please check our [tech guides](https://github.com/rootstrap/tech-guides). Keep in mind that the more you know about these guides, the easier it will be for your code to get approved and merged.
38
-
39
- Note: We work with one commit per pull request, so if you make your commit and realize you were missing something or want to add something more to it, don't create a new commit with the changes, but use `$ git commit --amend` instead. This same principle also applies for when changes are requested on an open pull request.
40
-
41
-
42
- Thank you very much for your time and for considering helping in this project.
data/Gemfile DELETED
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- gemspec
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- task :code_analysis do
4
- sh 'bundle exec rubocop lib spec'
5
- sh 'bundle exec reek lib'
6
- end
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'bundler/setup'
5
- require 'yaaf'
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require 'irb'
15
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,15 +0,0 @@
1
- # 📖 Documentation
2
-
3
- ## Usage
4
-
5
- [Check usage section in the main README](https://github.com/rootstrap/yaaf/blob/master/README.md#usage)
6
-
7
- ## Recipes
8
-
9
- - [YAAF with Simple Form](recipes/simple_form.md)
10
-
11
- ## Credits
12
-
13
- YAAF is maintained by [Rootstrap](http://www.rootstrap.com) with the help of our [contributors](https://github.com/rootstrap/yaaf/contributors).
14
-
15
- [<img src="https://s3-us-west-1.amazonaws.com/rootstrap.com/img/rs.png" width="100"/>](http://www.rootstrap.com)
@@ -1,117 +0,0 @@
1
- # Using YAAF with Simple Form
2
-
3
- [Simple Form](https://github.com/heartcombo/simple_form) is a gem to create visual forms in an easy and flexible manner.
4
-
5
- ## Usage
6
-
7
- Pass a `YAAF::Form` object instance to the `simple_form_for` helper method.
8
-
9
- For example, in a library management system (a pretty miminal one), the form to create books will look like this:
10
-
11
- ```ruby
12
- # app/forms/book_form.rb
13
-
14
- class BookForm < YAAF::Form
15
- attr_accessor :name, :isbn
16
-
17
- def initialize(attributes)
18
- super(attributes)
19
-
20
- @models = [book]
21
- end
22
-
23
- def book
24
- @book ||= Book.new(name: name, isbn: isbn)
25
- end
26
- end
27
- ```
28
-
29
-
30
- ```ruby
31
- # app/controllers/books_controller.rb
32
-
33
- class BooksController < ApplicationController
34
- def new
35
- @book = BookForm.new
36
- end
37
- end
38
- ```
39
-
40
- ```erb
41
- <%# app/views/books/new.html.erb %>
42
-
43
- <%= simple_form_for(@book, method: :post, url: books_path) do |f| %>
44
- <%= f.input :name %>
45
- <%= f.input :isbn %>
46
-
47
- <%= f.submit 'Create Book' %>
48
- <% end %>
49
- ```
50
-
51
- ## I18n
52
-
53
- In order to make use of translations correctly, we should pass an `as` value to the `simple_form_for` helper method.
54
-
55
- ```erb
56
- <%# app/views/books/new.html.erb %>
57
-
58
- <%= simple_form_for(@book, as: :book, ...) do |f| %>
59
- ...
60
- ```
61
-
62
- So you now can write your translations as:
63
-
64
- ```yaml
65
- # app/config/locales/simple_form.en.yml
66
-
67
- en:
68
- simple_form:
69
- ...
70
-
71
- labels:
72
- book:
73
- name: Book Name
74
- isbn: International Standard Book Number
75
- ```
76
-
77
- When using the `f.submit` helper method from Simple Form, the method `model_name` will be used to display the
78
- button's text. If this is not defined it will display: "Create Book Form".
79
- You can use a translation directly in the view to avoid overriding this method.
80
-
81
- ```ruby
82
- # app/forms/book_form.rb
83
-
84
- ...
85
-
86
- def model_name
87
- Book.model_name
88
- end
89
-
90
- ...
91
- ```
92
-
93
- More info about how Simple Form translates forms [here](https://github.com/heartcombo/simple_form#i18n).
94
-
95
- ## Persisted?
96
-
97
- Define the `persisted?` method in your form object to let Simple Form know if the object is being created or upated.
98
-
99
- ```ruby
100
- # app/forms/book_form.rb
101
-
102
- ...
103
-
104
- def persisted?
105
- book.persisted? # Or you can directly make it return false
106
- end
107
-
108
- ...
109
- ```
110
-
111
- ## Got questions?
112
-
113
- Feel free to [create an issue](https://github.com/rootstrap/yaaf/issues) and we'll discuss about it.
114
-
115
- YAAF is maintained by [Rootstrap](http://www.rootstrap.com) with the help of our [contributors](https://github.com/rootstrap/yaaf/contributors).
116
-
117
- [<img src="https://s3-us-west-1.amazonaws.com/rootstrap.com/img/rs.png" width="100"/>](http://www.rootstrap.com)
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/yaaf/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'yaaf'
7
- spec.version = YAAF::VERSION
8
- spec.authors = ['Juan Manuel Ramallo', 'Santiago Bartesaghi']
9
- spec.email = ['juan.ramallo@rootstrap.com']
10
-
11
- spec.summary = 'Easing the form object pattern in Rails applications.'
12
- spec.homepage = 'https://github.com/rootstrap/yaaf'
13
- spec.license = 'MIT'
14
- spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
15
-
16
- spec.metadata['homepage_uri'] = spec.homepage
17
- spec.metadata['source_code_uri'] = 'https://github.com/rootstrap/yaaf'
18
-
19
- # Specify which files should be added to the gem when it is released.
20
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
- end
24
- spec.bindir = 'exe'
25
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
- spec.require_paths = ['lib']
27
-
28
- # # Production dependencies
29
- spec.add_dependency 'activemodel', ['>= 4', '< 7']
30
- spec.add_dependency 'activerecord', ['>= 4', '< 7']
31
-
32
- spec.add_development_dependency 'database_cleaner-active_record', '~> 1.8.0'
33
- spec.add_development_dependency 'rake', '~> 13.0.1'
34
- spec.add_development_dependency 'reek', '~> 5.6.0'
35
- spec.add_development_dependency 'rspec', '~> 3.9.0'
36
- spec.add_development_dependency 'rubocop', '~> 0.80.0'
37
- spec.add_development_dependency 'simplecov', '~> 0.17.1'
38
- spec.add_development_dependency 'sqlite3', '~> 1.4.2'
39
- end