attr_filters 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +17 -0
- data/.travis.yml +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +21 -0
- data/README.md +89 -0
- data/Rakefile +8 -0
- data/attr_filters.gemspec +40 -0
- data/bin/console +15 -0
- data/bin/rubocop +29 -0
- data/bin/setup +8 -0
- data/lib/attr_filters.rb +18 -0
- data/lib/attr_filters/filters.rb +25 -0
- data/lib/attr_filters/filters/base.rb +11 -0
- data/lib/attr_filters/filters/capitalize.rb +13 -0
- data/lib/attr_filters/filters/downcase.rb +13 -0
- data/lib/attr_filters/filters/letters_only.rb +13 -0
- data/lib/attr_filters/filters/numbers_only.rb +13 -0
- data/lib/attr_filters/filters/squeeze.rb +13 -0
- data/lib/attr_filters/filters/trim.rb +13 -0
- data/lib/attr_filters/filters/upcase.rb +13 -0
- data/lib/attr_filters/filters_macro.rb +51 -0
- data/lib/attr_filters/instance_methods.rb +21 -0
- data/lib/attr_filters/utils.rb +11 -0
- data/lib/attr_filters/version.rb +5 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e4455bcc65da210b6511a8c694527be623766d51c8b68fb9548aa5a13a9dae6b
|
4
|
+
data.tar.gz: 18e30cc46d335a005a2f4fd39c458733fe01d5ad033bf077bf24e80b02c90110
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f2d31b7b6abac32bf7969a0efcabcc1fd9fdad148ab10c74bea7fc6d192dac42c87fb526c312d29311a8b091ea3ad2e82c3e89f76f25fa5eb740869ce6360138
|
7
|
+
data.tar.gz: 6f3f9a6381cfa7335df539da2180666509bbaf070d9fcb45cbbcf005774d80a4b715ba7032b46b763cd9a0f9772b5c6c8b03bfbe06b3812c91f9b7a947490863
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Style/StringLiterals:
|
2
|
+
EnforcedStyle: double_quotes
|
3
|
+
Style/BlockDelimiters:
|
4
|
+
Exclude:
|
5
|
+
- "spec/**/*"
|
6
|
+
|
7
|
+
Metrics/LineLength:
|
8
|
+
Max: 120
|
9
|
+
Metrics/BlockLength:
|
10
|
+
Exclude:
|
11
|
+
- "spec/**/*"
|
12
|
+
|
13
|
+
Layout/IndentationConsistency:
|
14
|
+
EnforcedStyle: indented_internal_methods
|
15
|
+
|
16
|
+
Documentation:
|
17
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 kelevro88@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
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
attr_filters (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.0)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
jaro_winkler (1.5.3)
|
12
|
+
parallel (1.18.0)
|
13
|
+
parser (2.6.5.0)
|
14
|
+
ast (~> 2.4.0)
|
15
|
+
rainbow (3.0.0)
|
16
|
+
rake (10.5.0)
|
17
|
+
rspec (3.9.0)
|
18
|
+
rspec-core (~> 3.9.0)
|
19
|
+
rspec-expectations (~> 3.9.0)
|
20
|
+
rspec-mocks (~> 3.9.0)
|
21
|
+
rspec-core (3.9.0)
|
22
|
+
rspec-support (~> 3.9.0)
|
23
|
+
rspec-expectations (3.9.0)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.9.0)
|
26
|
+
rspec-mocks (3.9.0)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.9.0)
|
29
|
+
rspec-support (3.9.0)
|
30
|
+
rubocop (0.75.1)
|
31
|
+
jaro_winkler (~> 1.5.1)
|
32
|
+
parallel (~> 1.10)
|
33
|
+
parser (>= 2.6)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
ruby-progressbar (~> 1.7)
|
36
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
37
|
+
ruby-progressbar (1.10.1)
|
38
|
+
unicode-display_width (1.6.0)
|
39
|
+
|
40
|
+
PLATFORMS
|
41
|
+
ruby
|
42
|
+
|
43
|
+
DEPENDENCIES
|
44
|
+
attr_filters!
|
45
|
+
bundler (~> 2.0)
|
46
|
+
rake (~> 10.0)
|
47
|
+
rspec (~> 3.0)
|
48
|
+
rubocop (~> 0.75.0)
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Anton Holovko
|
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,89 @@
|
|
1
|
+
# AttrFilters
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.com/Syndicode/attr-filters.svg?branch=master)](https://travis-ci.com/Syndicode/attr-filters)
|
4
|
+
|
5
|
+
Light weight gem for filtering PORO attributes with zero dependencies.
|
6
|
+
|
7
|
+
## Description
|
8
|
+
|
9
|
+
AttrFilters brings simple DSL for adding filters to your PORO attributes.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'attr_filters'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install attr_filters
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
You can add filters like that:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
class SingupForm
|
33
|
+
include AttrFilters
|
34
|
+
|
35
|
+
attr_accessor :email, :first_name, :last_name, :zip
|
36
|
+
|
37
|
+
filters :email, trim: true, downcase: true
|
38
|
+
filters :first_name, :last_name, trim: true, letters_only: true
|
39
|
+
filters :zip, trim: true, numbers_only: true
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
And call `#filter!` method to apply filters for attributes values
|
44
|
+
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
form = SingupForm.new
|
48
|
+
|
49
|
+
form.email = " mike.dou@example.com "
|
50
|
+
form.first_name = "Mike 123"
|
51
|
+
form.last_name = " Dou"
|
52
|
+
form.zip = "abc12345"
|
53
|
+
|
54
|
+
form.filter!
|
55
|
+
|
56
|
+
form.email # => "mike.dou@example.com"
|
57
|
+
form.first_name # => "Mike"
|
58
|
+
form.last_name # => "Dou"
|
59
|
+
form.zip # => "12345"
|
60
|
+
```
|
61
|
+
|
62
|
+
## Available Filters
|
63
|
+
|
64
|
+
- `trim` - removes leading and trailing whitespaces
|
65
|
+
- `downcase` - replaces all upcase letters to lowercase ones
|
66
|
+
- `upcase` - replaces all lowercase letters to upcase ones
|
67
|
+
- `capitalize` - upcases first letter and lowercase others
|
68
|
+
- `squeeze` - removes duplicating whitespaces
|
69
|
+
- `numbers_only` - removes non digits characters
|
70
|
+
- `letters_only` - removes non letter characters
|
71
|
+
|
72
|
+
|
73
|
+
## Development
|
74
|
+
|
75
|
+
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.
|
76
|
+
|
77
|
+
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).
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/attr_filters. 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.
|
82
|
+
|
83
|
+
## License
|
84
|
+
|
85
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
86
|
+
|
87
|
+
## Code of Conduct
|
88
|
+
|
89
|
+
Everyone interacting in the AttrFilters project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/attr_filters/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require "attr_filters/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "attr_filters"
|
9
|
+
spec.version = AttrFilters::VERSION
|
10
|
+
spec.authors = ["Anton Holovko", "Syndicode LLC"]
|
11
|
+
spec.email = ["anton.holovko.b@gmail.com", "info@syndicode.com"]
|
12
|
+
|
13
|
+
spec.summary = "Light weight gem for filtering PORO attributes with zero dependencies."
|
14
|
+
spec.description = "Brings simple DSL for filtering attributes value in PORO"
|
15
|
+
spec.homepage = "https://github.com/Syndicode/attr-filters"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/Syndicode/attr-filters"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/Syndicode/attr-filters"
|
22
|
+
else
|
23
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
24
|
+
"public gem pushes."
|
25
|
+
end
|
26
|
+
|
27
|
+
# Specify which files should be added to the gem when it is released.
|
28
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
29
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
30
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
31
|
+
end
|
32
|
+
spec.bindir = "exe"
|
33
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
34
|
+
spec.require_paths = ["lib"]
|
35
|
+
|
36
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
37
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
38
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
39
|
+
spec.add_development_dependency "rubocop", "~> 0.75.0"
|
40
|
+
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 "attr_filters"
|
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/rubocop
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rubocop' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rubocop", "rubocop")
|
data/bin/setup
ADDED
data/lib/attr_filters.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "attr_filters/version"
|
4
|
+
|
5
|
+
module AttrFilters
|
6
|
+
class UnknownFilterError < StandardError; end
|
7
|
+
class UnknownAttributeError < StandardError; end
|
8
|
+
|
9
|
+
autoload :Utils, "attr_filters/utils"
|
10
|
+
autoload :FiltersMacro, "attr_filters/filters_macro"
|
11
|
+
autoload :InstanceMethods, "attr_filters/instance_methods"
|
12
|
+
autoload :Filters, "attr_filters/filters"
|
13
|
+
|
14
|
+
def self.included(base)
|
15
|
+
base.extend(FiltersMacro)
|
16
|
+
base.include(InstanceMethods)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AttrFilters
|
4
|
+
module Filters
|
5
|
+
autoload :Base, "attr_filters/filters/base"
|
6
|
+
|
7
|
+
autoload :Trim, "attr_filters/filters/trim"
|
8
|
+
autoload :Downcase, "attr_filters/filters/downcase"
|
9
|
+
autoload :Upcase, "attr_filters/filters/upcase"
|
10
|
+
autoload :Capitalize, "attr_filters/filters/capitalize"
|
11
|
+
autoload :Squeeze, "attr_filters/filters/squeeze"
|
12
|
+
autoload :LettersOnly, "attr_filters/filters/letters_only"
|
13
|
+
autoload :NumbersOnly, "attr_filters/filters/numbers_only"
|
14
|
+
|
15
|
+
LIST = {
|
16
|
+
trim: Trim.new,
|
17
|
+
downcase: Downcase.new,
|
18
|
+
upcase: Upcase.new,
|
19
|
+
numbers_only: NumbersOnly.new,
|
20
|
+
letters_only: LettersOnly.new,
|
21
|
+
squeeze: Squeeze.new,
|
22
|
+
capitalize: Capitalize.new
|
23
|
+
}.freeze
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AttrFilters
|
4
|
+
module FiltersMacro
|
5
|
+
def filters(*attributes)
|
6
|
+
@_registered_filters ||= {}
|
7
|
+
|
8
|
+
attrs, filters = AttrFilters::Utils.extract_options(attributes)
|
9
|
+
|
10
|
+
check_attributes!(attrs)
|
11
|
+
check_filters!(filters.keys)
|
12
|
+
|
13
|
+
register_filters(filters, attrs)
|
14
|
+
end
|
15
|
+
|
16
|
+
def _registered_filters
|
17
|
+
@_registered_filters
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def register_filters(filters, attrs)
|
23
|
+
filters.each_pair do |filter, _options|
|
24
|
+
@_registered_filters[filter] ||= Set.new
|
25
|
+
@_registered_filters[filter].merge(attrs)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def check_attributes!(attrs)
|
30
|
+
attrs.each do |attr|
|
31
|
+
setter = "#{attr}="
|
32
|
+
unknown_attribute!(setter) unless method_defined?(setter)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def check_filters!(filters)
|
37
|
+
filters.each do |filter|
|
38
|
+
unknown_filter!(filter) unless AttrFilters::Filters::LIST.key?(filter)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def unknown_filter!(filter_name)
|
43
|
+
filters_list = AttrFilters::Filters::LIST.keys.join(", ")
|
44
|
+
raise(AttrFilters::UnknownFilterError, "Unknown filter '#{filter_name}'. Available are [#{filters_list}]")
|
45
|
+
end
|
46
|
+
|
47
|
+
def unknown_attribute!(attr)
|
48
|
+
raise AttrFilters::UnknownAttributeError, "Unknown attribute #{attr}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AttrFilters
|
4
|
+
module InstanceMethods
|
5
|
+
def filter!
|
6
|
+
self.class._registered_filters.each_pair do |filter_name, attrs|
|
7
|
+
filter = build_filter(filter_name)
|
8
|
+
attrs.each do |attr|
|
9
|
+
value = send(attr)
|
10
|
+
send("#{attr}=", filter.call(value))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def build_filter(filter_name)
|
18
|
+
AttrFilters::Filters::LIST[filter_name]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: attr_filters
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anton Holovko
|
8
|
+
- Syndicode LLC
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2019-10-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '2.0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '2.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rubocop
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.75.0
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.75.0
|
70
|
+
description: Brings simple DSL for filtering attributes value in PORO
|
71
|
+
email:
|
72
|
+
- anton.holovko.b@gmail.com
|
73
|
+
- info@syndicode.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".rubocop.yml"
|
81
|
+
- ".travis.yml"
|
82
|
+
- CODE_OF_CONDUCT.md
|
83
|
+
- Gemfile
|
84
|
+
- Gemfile.lock
|
85
|
+
- LICENSE.txt
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- attr_filters.gemspec
|
89
|
+
- bin/console
|
90
|
+
- bin/rubocop
|
91
|
+
- bin/setup
|
92
|
+
- lib/attr_filters.rb
|
93
|
+
- lib/attr_filters/filters.rb
|
94
|
+
- lib/attr_filters/filters/base.rb
|
95
|
+
- lib/attr_filters/filters/capitalize.rb
|
96
|
+
- lib/attr_filters/filters/downcase.rb
|
97
|
+
- lib/attr_filters/filters/letters_only.rb
|
98
|
+
- lib/attr_filters/filters/numbers_only.rb
|
99
|
+
- lib/attr_filters/filters/squeeze.rb
|
100
|
+
- lib/attr_filters/filters/trim.rb
|
101
|
+
- lib/attr_filters/filters/upcase.rb
|
102
|
+
- lib/attr_filters/filters_macro.rb
|
103
|
+
- lib/attr_filters/instance_methods.rb
|
104
|
+
- lib/attr_filters/utils.rb
|
105
|
+
- lib/attr_filters/version.rb
|
106
|
+
homepage: https://github.com/Syndicode/attr-filters
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata:
|
110
|
+
homepage_uri: https://github.com/Syndicode/attr-filters
|
111
|
+
source_code_uri: https://github.com/Syndicode/attr-filters
|
112
|
+
changelog_uri: https://github.com/Syndicode/attr-filters
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.7.6
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Light weight gem for filtering PORO attributes with zero dependencies.
|
133
|
+
test_files: []
|