formify 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e6986f5a092a5b5c13abbd8daeff88ea4571d69b647db4684843ef1107704434
4
+ data.tar.gz: 401a723a94bd78ef45c677f1b32435b037ce76785f37cfad18ddb731c1d086f7
5
+ SHA512:
6
+ metadata.gz: dae0ce0a184c7793fa3880b14a956ea9a4c4fcde301d251a6ef7e5220d9939a076480537eb20150cd6df100f958cb8971a51c3f2dd91234aaec0781f1e2acc5d
7
+ data.tar.gz: 5cafd37279bedd6aa9ae96e37e286de0be761b1c5f2a65e798e00ff1ad1aac173e41616a64033a3ad0b2f334278692e04be4fa3f10a1db7e2bb46069288edb36
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 2.0.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 0.1.0
2
+
3
+ Initial release.
@@ -0,0 +1,74 @@
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 ryanwjackson@gmail.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 [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in formify.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ formify (0.1.0)
5
+ resonad
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ rake (10.5.0)
12
+ resonad (1.2.0)
13
+ rspec (3.8.0)
14
+ rspec-core (~> 3.8.0)
15
+ rspec-expectations (~> 3.8.0)
16
+ rspec-mocks (~> 3.8.0)
17
+ rspec-core (3.8.0)
18
+ rspec-support (~> 3.8.0)
19
+ rspec-expectations (3.8.3)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.8.0)
22
+ rspec-mocks (3.8.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.8.0)
25
+ rspec-support (3.8.0)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 2.0)
32
+ formify!
33
+ rake (~> 10.0)
34
+ rspec (~> 3.0)
35
+
36
+ BUNDLED WITH
37
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Ryan Jackson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Formify
2
+
3
+ Formify gives you scaffolding for quickly adding robust forms to your application. Formify also includes rspec testing helpers, making it easy to validate forms.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'formify'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install formify
20
+
21
+ ## Usage
22
+
23
+ Once installed, use `include Formify::Form` into any class to give it the form structure.
24
+
25
+ ## Development
26
+
27
+ After 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.
28
+
29
+ To 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).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ryanwjackson/formify. 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.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
38
+
39
+ ## Code of Conduct
40
+
41
+ Everyone interacting in the Formify project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ryanwjackson/formify/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "formify"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
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
data/formify.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'formify/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'formify'
7
+ spec.version = Formify::VERSION
8
+ spec.authors = ['Ryan Jackson']
9
+ spec.email = ['ryanwjackson@gmail.com']
10
+
11
+ spec.summary = 'Formify gives structure to using form objects in a Rails project.'
12
+ spec.description = 'Formify acts as an abstract class, allowing you to easily create robust form objects and test them using rspec.'
13
+ spec.homepage = 'https://www.github.com/ryanwjackson/formify'
14
+ spec.license = 'MIT'
15
+
16
+ # # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = 'rubygems.org'
20
+ # spec.metadata['homepage_uri'] = spec.homepage
21
+ # spec.metadata['source_code_uri'] = spec.homepage
22
+ # spec.metadata['changelog_uri'] = 'https://github.com/ryanwjackson/formify/blob/master/CHANGELOG.md'
23
+ # else
24
+ # raise 'RubyGems 2.0 or newer is required to protect against ' \
25
+ # 'public gem pushes.'
26
+ # end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = 'exe'
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ['lib']
36
+
37
+ spec.add_development_dependency 'bundler', '~> 2.0'
38
+ spec.add_development_dependency 'rake', '~> 10.0'
39
+ spec.add_development_dependency 'rspec', '~> 3.0'
40
+ spec.add_runtime_dependency 'resonad'
41
+ end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Formify
4
+ module Form
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ include ActiveModel::Model
9
+ include ActiveModel::Validations
10
+ include ActiveModel::Validations::Callbacks
11
+
12
+ def t(*args, **keywords)
13
+ I18n.t(*args, **keywords)
14
+ end
15
+
16
+ def validate_or_fail(*instances)
17
+ unless valid?
18
+ return Resonad.Failure(
19
+ Forms::Errors::ValidationError.new(form: self)
20
+ )
21
+ end
22
+
23
+ if instances.present?
24
+ instances.each do |instance|
25
+ next if instance.valid?
26
+
27
+ return Resonad.Failure(
28
+ Forms::Errors::ValidationError.new(form: self, message: instance.full_messages.first)
29
+ )
30
+ end
31
+ end
32
+
33
+ Resonad.Success
34
+ end
35
+
36
+ def return_self
37
+ Resonad.Success(self)
38
+ end
39
+
40
+ def translation_data
41
+ {}
42
+ end
43
+
44
+ def translation_success
45
+ split_name = self.class.name.split('::')
46
+ split_name.shift
47
+ action = split_name.pop.underscore
48
+ key = split_name.map(&:underscore).push(action).push(:success).join('.')
49
+ return t(key) if I18n.exists?(key, translation_data)
50
+ end
51
+
52
+ def with_advisory_lock(*keys, **args)
53
+ key = keys.map do |k|
54
+ if k.is_a?(String)
55
+ k
56
+ else
57
+ k.try(:id)
58
+ end
59
+ end.join('/')
60
+ ActiveRecord::Base.with_advisory_lock(key, **args) { yield }
61
+ end
62
+
63
+ def with_advisory_lock_transaction(*keys)
64
+ with_advisory_lock_transaction_result = Resonad.Failure
65
+
66
+ with_advisory_lock(*keys, transaction: true) do
67
+ ActiveRecord::Base.transaction do
68
+ with_advisory_lock_transaction_result = begin
69
+ yield
70
+ end
71
+
72
+ raise ActiveRecord::Rollback if with_advisory_lock_transaction_result.failure?
73
+ end
74
+ end
75
+
76
+ with_advisory_lock_transaction_result
77
+ end
78
+
79
+ def params
80
+ self.class.params
81
+ end
82
+ end
83
+
84
+ class_methods do
85
+ def attr_accessor(*attrs)
86
+ @class_params ||= []
87
+ @class_params.concat(attrs)
88
+ super(*attrs)
89
+ end
90
+
91
+ def delegate_accessor(*args, **keywords)
92
+ delegate(
93
+ *args.map { |arg| [arg, "#{arg}="] }.flatten,
94
+ **keywords
95
+ )
96
+ end
97
+
98
+ def params
99
+ @params ||= @class_params.reject { |e| %i[validation_context].include?(e) }
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Formify
4
+ module SpecHelpers
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ let(:form) { described_class }
9
+ let(:initialized_form) { initialize_form }
10
+ let(:attributes_override) { {} }
11
+ let(:attributes_to_pass) { attributes.merge(attributes_override) }
12
+
13
+ let(:result) { do_result }
14
+
15
+ let(:value) { do_value }
16
+
17
+ let(:error) { result.error }
18
+ let(:error_message) { result.error.message }
19
+
20
+ def do_result
21
+ initialized_form.save
22
+ end
23
+
24
+ def do_value
25
+ result.value
26
+ end
27
+
28
+ def initialize_form
29
+ form.new(attributes_to_pass)
30
+ end
31
+
32
+ # Common Expectation Helpers
33
+
34
+ def expect_error_message(message)
35
+ expect(error_message).to include(message)
36
+ end
37
+
38
+ def expect_error_with_attribute(attribute)
39
+ expect(error.attribute.try(:to_sym)).to eq(attribute.to_sym)
40
+ end
41
+
42
+ def expect_error_with_attribute_value(attribute, value)
43
+ initialized_form.send("#{attribute}=", value)
44
+ expect_error_with_attribute(attribute)
45
+ end
46
+
47
+ def expect_error_with_missing_attribute(attribute)
48
+ raise 'No attribute' unless attributes.key?(attribute)
49
+
50
+ attributes_to_pass.delete(attribute)
51
+ expect_error_with_attribute(attribute)
52
+ end
53
+
54
+ def expect_invalid(*args, **keywords)
55
+ expect_not_valid(*args, **keywords)
56
+ end
57
+
58
+ def expect_not_valid(attribute: nil, message: nil)
59
+ expect_error_with_attribute(attribute) if attribute.present?
60
+ expect_error_message(message) if message.present?
61
+
62
+ expect(initialized_form).not_to be_valid
63
+ end
64
+
65
+ def expect_valid
66
+ expect(initialized_form).to be_valid
67
+ end
68
+
69
+ def expect_valid_with_attribute_value(attribute, value)
70
+ initialized_form.send("#{attribute}=", value)
71
+ expect_valid
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,3 @@
1
+ module Formify
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/lib/formify.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "formify/version"
2
+ require "resonad"
3
+
4
+ module Formify
5
+ class Error < StandardError; end
6
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: formify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Jackson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: resonad
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Formify acts as an abstract class, allowing you to easily create robust
70
+ form objects and test them using rspec.
71
+ email:
72
+ - ryanwjackson@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CHANGELOG.md
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/setup
89
+ - formify.gemspec
90
+ - lib/formify.rb
91
+ - lib/formify/form.rb
92
+ - lib/formify/spec_helpers.rb
93
+ - lib/formify/version.rb
94
+ homepage: https://www.github.com/ryanwjackson/formify
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.7.6
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Formify gives structure to using form objects in a Rails project.
118
+ test_files: []