active_errors 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4911a8ccfdc5c06d4801cf7a63e9e1bceaa6e73397f0a37684e029f2731ddcfb
4
+ data.tar.gz: 9dddce1eebd8e8609d5702ca0317ed698ce302d92f623726ebe0ee63cfd426f0
5
+ SHA512:
6
+ metadata.gz: 9fbb9ed5f94ef41ab28088c739e593a0f8b2658d54e2a9bd353aefe75a77c36a61e4752370ca2ea26be50de8513282aae620102f6f433b108c55c9b037db646b
7
+ data.tar.gz: f15e21672463e7fa8055e043d6df01f1c97cfca6a3e4e566618d1cab59599943358da6f2d060d1a54aab49c4a2f65e97f1e0397420a928ba4534f413c83a0088
data/.fasterer.yml ADDED
@@ -0,0 +1,19 @@
1
+ speedups:
2
+ rescue_vs_respond_to: true
3
+ module_eval: true
4
+ shuffle_first_vs_sample: true
5
+ for_loop_vs_each: true
6
+ each_with_index_vs_while: false
7
+ map_flatten_vs_flat_map: true
8
+ reverse_each_vs_reverse_each: true
9
+ select_first_vs_detect: true
10
+ sort_vs_sort_by: true
11
+ fetch_with_argument_vs_block: true
12
+ keys_each_vs_each_key: true
13
+ hash_merge_bang_vs_hash_brackets: true
14
+ block_vs_symbol_to_proc: true
15
+ proc_call_vs_yield: true
16
+ gsub_vs_tr: true
17
+ select_last_vs_reverse_detect: true
18
+ getter_vs_attr_reader: true
19
+ setter_vs_attr_writer: true
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.irbrc_history
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.irbrc ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Awesome print
4
+ begin
5
+ require 'awesome_print'
6
+
7
+ AwesomePrint.irb!
8
+ rescue LoadError => err
9
+ warn "Couldn't load awesome_print: #{err}"
10
+ end
11
+
12
+ # IRB
13
+ require 'irb/completion'
14
+
15
+ ARGV.concat %w[--readline --prompt-mode simple]
16
+
17
+ IRB.conf[:PROMPT_MODE] = :SIMPLE
18
+ IRB.conf[:EVAL_HISTORY] = 1000
19
+ IRB.conf[:SAVE_HISTORY] = 1000
20
+ IRB.conf[:HISTORY_FILE] = File.expand_path('.irbrc_history')
21
+
22
+ # Rails
23
+ railsrc_path = File.expand_path('.irbrc_rails')
24
+
25
+ if (ENV['RAILS_ENV'] || defined?(Rails)) && File.exist?(railsrc_path)
26
+ begin
27
+ load railsrc_path
28
+ rescue Exception => err
29
+ warn "Could not load: #{railsrc_path} because of #{err}"
30
+ end
31
+ end
32
+
33
+ # Object
34
+ class Object
35
+
36
+ def interesting_methods
37
+ case self.class
38
+ when Class then public_methods.sort - Object.public_methods
39
+ when Module then public_methods.sort - Module.public_methods
40
+ else public_methods.sort - Object.new.public_methods
41
+ end
42
+ end
43
+
44
+ end
data/.reek.yml ADDED
@@ -0,0 +1,26 @@
1
+ ---
2
+ detectors:
3
+ Attribute:
4
+ enabled: false
5
+ BooleanParameter:
6
+ enabled: false
7
+ ControlParameter:
8
+ enabled: false
9
+ FeatureEnvy:
10
+ enabled: false
11
+ IrresponsibleModule:
12
+ enabled: false
13
+ ManualDispatch:
14
+ enabled: false
15
+ NestedIterators:
16
+ max_allowed_nesting: 2
17
+ NilCheck:
18
+ enabled: false
19
+ TooManyStatements:
20
+ max_statements: 10
21
+ UncommunicativeVariableName:
22
+ accept:
23
+ - '/^.$/'
24
+ - '/[0-9]$/'
25
+ UtilityFunction:
26
+ enabled: false
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --backtrace
2
+ --color
3
+ --format progress
4
+ --order random
data/.rubocop.yml ADDED
@@ -0,0 +1,30 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ DisplayStyleGuide: true
4
+ TargetRubyVersion: 2.5
5
+ Exclude:
6
+ - 'spec/**/**/*'
7
+ Performance/RegexpMatch:
8
+ Enabled: false
9
+ Layout/EmptyLinesAroundClassBody:
10
+ Enabled: false
11
+ Layout/EmptyLinesAroundModuleBody:
12
+ Enabled: false
13
+ LineLength:
14
+ Max: 100
15
+ Lint/RescueException:
16
+ Enabled: false
17
+ Metrics/ModuleLength:
18
+ Enabled: false
19
+ Style/Alias:
20
+ EnforcedStyle: prefer_alias_method
21
+ Style/ClassAndModuleChildren:
22
+ Enabled: false
23
+ Style/Documentation:
24
+ Enabled: false
25
+ Style/ExpandPathArguments:
26
+ Enabled: false
27
+ Style/RescueModifier:
28
+ Enabled: false
29
+ Style/RescueStandardError:
30
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - ruby-head
5
+ before_install:
6
+ - sudo apt-get install libxml2-dev
7
+ - gem update --system
8
+ - gem install bundler
9
+ - bundle install
10
+ script:
11
+ - bundle exec rake
12
+ notifications:
13
+ disable: true
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in active_object.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Juan Gomez
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,64 @@
1
+ # ActiveErrors
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/active_errors.svg)](http://badge.fury.io/rb/active_errors)
4
+ [![Build Status](https://travis-ci.org/drexed/active_errors.svg?branch=master)](https://travis-ci.org/drexed/active_errors)
5
+
6
+ ActiveErrors provides an API for generating and accessing in the identical format as ActiveModel::Errors but without the need for all those extra cruft.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'active_errors'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install active_errors
23
+
24
+ ## Table of Contents
25
+
26
+ * [Usage](#usage)
27
+
28
+ ## Usage
29
+
30
+ ```ruby
31
+ class Shipment
32
+
33
+ def errors
34
+ @errors ||= ActiveErrors::Messages.new
35
+ end
36
+
37
+ def messages
38
+ @errors.full_messages
39
+ end
40
+
41
+ def process
42
+ ShipmentItem.each do |item|
43
+ item.add_to_box!
44
+ rescue Shipment::OutOfStock => e
45
+ errors.add(item.name, I18n.t('errors.out_of_stock'))
46
+ rescue Shipment::DoesNotExist => e
47
+ errors[item.name] = I18n.t('errors.does_not_exist')
48
+ rescue ActiveRecord::RecordInvalid
49
+ errors.merge!(item.errors)
50
+ end
51
+ end
52
+
53
+ end
54
+ ```
55
+
56
+ ## Contributing
57
+
58
+ Your contribution is welcome.
59
+
60
+ 1. Fork it
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+
5
+ task default: :spec
data/_config.yml ADDED
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-cayman
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'active_errors/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'active_errors'
9
+ spec.version = ActiveErrors::VERSION
10
+ spec.authors = ['Juan Gomez']
11
+ spec.email = ['j.gomez@drexed.com']
12
+
13
+ spec.summary = 'Gem for generating and accessing ActiveModel::Errors like error messages.'
14
+ spec.description = 'Generate and access ActiveModel::Errors like error messages.'
15
+ spec.homepage = 'http://drexed.github.io/active_errors'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'activerecord'
24
+ spec.add_development_dependency 'bundler'
25
+ spec.add_development_dependency 'database_cleaner'
26
+ spec.add_development_dependency 'fasterer'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'reek'
29
+ spec.add_development_dependency 'rspec'
30
+ spec.add_development_dependency 'rubocop'
31
+ spec.add_development_dependency 'sqlite3'
32
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'active_errors'
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
data/bin/rake ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rake' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath)
11
+
12
+ require 'rubygems'
13
+ require 'bundler/setup'
14
+
15
+ load Gem.bin_path('rake', 'rake')
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ %w[version messages].each do |file_name|
4
+ require "active_errors/#{file_name}"
5
+ end
@@ -0,0 +1,115 @@
1
+ module ActiveErrors
2
+ class Messages
3
+
4
+ attr_reader :errors
5
+
6
+ def initialize
7
+ @errors = {}
8
+ end
9
+
10
+ def [](key)
11
+ return [] unless @errors.key?(key)
12
+
13
+ @errors[key]
14
+ end
15
+
16
+ def []=(key, value)
17
+ @errors[key] ||= []
18
+ @errors[key] << value
19
+ @errors[key].uniq!
20
+ end
21
+
22
+ alias_method :add, :[]=
23
+
24
+ def added?(key, val)
25
+ return false unless @errors.key?(key)
26
+
27
+ @errors[key].include?(val)
28
+ end
29
+
30
+ def clear
31
+ @errors.clear
32
+ end
33
+
34
+ def delete(key)
35
+ @errors.delete(key)
36
+ end
37
+
38
+ # :nocov:
39
+ def each
40
+ @errors.each_key do |key|
41
+ @errors[key].each { |val| yield(key, val) }
42
+ end
43
+ end
44
+ # :nocov:
45
+
46
+ def empty?
47
+ @errors.empty?
48
+ end
49
+
50
+ alias_method :blank?, :empty?
51
+
52
+ def full_message(key, value)
53
+ "#{key} #{value}"
54
+ end
55
+
56
+ def full_messages
57
+ @errors.each_with_object([]) do |(key, arr), memo|
58
+ arr.each { |val| memo << full_message(key, val) }
59
+ end
60
+ end
61
+
62
+ alias_method :to_a, :full_messages
63
+
64
+ def full_messages_for(key)
65
+ return [] unless @errors.key?(key)
66
+
67
+ @errors[key].map { |val| full_message(key, val) }
68
+ end
69
+
70
+ def key?(key)
71
+ @errors.key?(key)
72
+ end
73
+
74
+ alias_method :has_key?, :key?
75
+ alias_method :include?, :key?
76
+
77
+ def keys
78
+ @errors.keys
79
+ end
80
+
81
+ def merge!(hash)
82
+ @errors.merge!(hash) do |_, arr1, arr2|
83
+ arr3 = arr1 + arr2
84
+ arr3.uniq!
85
+ arr3
86
+ end
87
+ end
88
+
89
+ def present?
90
+ !blank?
91
+ end
92
+
93
+ def size
94
+ @errors.size
95
+ end
96
+
97
+ alias_method :count, :size
98
+
99
+ def to_hash(full_messages = false)
100
+ return @errors unless full_messages
101
+
102
+ @errors.each_with_object({}) do |(key, arr), memo|
103
+ memo[key] = arr.map { |val| full_message(key, val) }
104
+ end
105
+ end
106
+
107
+ alias_method :messages, :to_hash
108
+ alias_method :as_json, :to_hash
109
+
110
+ def values
111
+ @errors.values
112
+ end
113
+
114
+ end
115
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveErrors
4
+ VERSION ||= '1.0.0'
5
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_errors
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Juan Gomez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: database_cleaner
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fasterer
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: reek
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sqlite3
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Generate and access ActiveModel::Errors like error messages.
140
+ email:
141
+ - j.gomez@drexed.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".fasterer.yml"
147
+ - ".gitignore"
148
+ - ".irbrc"
149
+ - ".reek.yml"
150
+ - ".rspec"
151
+ - ".rubocop.yml"
152
+ - ".travis.yml"
153
+ - CODE_OF_CONDUCT.md
154
+ - Gemfile
155
+ - LICENSE.txt
156
+ - README.md
157
+ - Rakefile
158
+ - _config.yml
159
+ - active_errors.gemspec
160
+ - bin/console
161
+ - bin/rake
162
+ - bin/setup
163
+ - lib/active_errors.rb
164
+ - lib/active_errors/messages.rb
165
+ - lib/active_errors/version.rb
166
+ homepage: http://drexed.github.io/active_errors
167
+ licenses:
168
+ - MIT
169
+ metadata: {}
170
+ post_install_message:
171
+ rdoc_options: []
172
+ require_paths:
173
+ - lib
174
+ required_ruby_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ requirements: []
185
+ rubygems_version: 3.0.0
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: Gem for generating and accessing ActiveModel::Errors like error messages.
189
+ test_files: []