attr_filters 0.3.2 → 0.4.0

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: 1d7462f6d9eb45b31f802dd03559d35cb187af65ae95717f70f0688b4f235360
4
- data.tar.gz: 6fd639cc323eaa80e28b3be710dd5f6c9750e32af89ac8323678a23554360532
3
+ metadata.gz: a5d9621f613bdb9188c3e39ce6cc9d9c7d0d310fc7f3c5b1fe301e46f40250f4
4
+ data.tar.gz: aead70cf656f6fb587fd811b5c7a68e10464d0e291fe22e1360b374efce0a4d6
5
5
  SHA512:
6
- metadata.gz: 4d309deacfb33b904f986e3131d0c0b201b75baa3f52af20ed7e1840fb60215ca8d99960dd229dd254996cd48249e4c0d02dc6f78c64b3b6960cf8bafdfc244e
7
- data.tar.gz: fd84ad1a8c69b7a2efce914e1d408d10f8e55299192f5fe5868c4449e971f93d4329c960d9e611d52025ada54f51c31a3c845a3db65350e7baa7801c77abb95b
6
+ metadata.gz: 95e5e1a38c9405ea7f7e14b9770106afeaae9ab1ab3e0540c2d7d9fa74cc35cfe295f1ef73ab9f855876a68a98735039496a4d29eab0eea564af59bcc8782e5c
7
+ data.tar.gz: 7593f45e1d12da007104abc013eb98ebff60dc6d2dc6db13bb9892e3fd270ab0d50997568b72c7f159440ac000d68edc064f484901a95e63d37552506abdfa84
data/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.com/Syndicode/attr-filters.svg?branch=master)](https://travis-ci.com/Syndicode/attr-filters)
4
4
  [![Gem Version](https://badge.fury.io/rb/attr_filters.svg)](https://badge.fury.io/rb/attr_filters)
5
- [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FSyndicode%2Fattr-filters.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FSyndicode%2Fattr-filters?ref=badge_shield)
5
+ [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FSyndicode%2Fattr-filters.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2FSyndicode%2Fattr-filters?ref=badge_shield)
6
+
6
7
 
7
8
  Light weight gem for filtering PORO (Plain Old Ruby Objects) attributes with zero dependencies.
8
9
 
@@ -132,10 +133,11 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/Syndic
132
133
 
133
134
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
134
135
 
136
+
135
137
  ## Code of Conduct
136
138
 
137
139
  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/Syndicode/attr_filters/blob/master/CODE_OF_CONDUCT.md).
138
140
 
139
141
  ## Authors
140
142
 
141
- [Syndicode.com](https://syndicode.com)
143
+ [Syndicode.com](https://syndicode.com)
@@ -11,6 +11,7 @@ module AttrFilters
11
11
  autoload :Squeeze, "attr_filters/filters/squeeze"
12
12
  autoload :LettersOnly, "attr_filters/filters/letters_only"
13
13
  autoload :NumbersOnly, "attr_filters/filters/numbers_only"
14
+ autoload :Date, "attr_filters/filters/date"
14
15
 
15
16
  LIST = {
16
17
  trim: Trim.new,
@@ -19,7 +20,8 @@ module AttrFilters
19
20
  numbers_only: NumbersOnly.new,
20
21
  letters_only: LettersOnly.new,
21
22
  squeeze: Squeeze.new,
22
- capitalize: Capitalize.new
23
+ capitalize: Capitalize.new,
24
+ date: Date.new
23
25
  }.freeze
24
26
  end
25
27
  end
@@ -3,8 +3,9 @@
3
3
  module AttrFilters
4
4
  module Filters
5
5
  class Base
6
- def call(value)
7
- filter(value)
6
+ def call(value, *options)
7
+ filter(value, *options.reject { |opt| opt == true })
8
+ rescue ::StandardError # rubocop:disable Lint/HandleExceptions
8
9
  end
9
10
  end
10
11
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AttrFilters
4
+ module Filters
5
+ class Date < Base
6
+ DEFAULT_FORMAT = "%Y-%m-%d"
7
+
8
+ private
9
+
10
+ def filter(value, format = DEFAULT_FORMAT)
11
+ ::Date.strptime(value, format)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -20,9 +20,9 @@ module AttrFilters
20
20
  private
21
21
 
22
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)
23
+ filters.each_pair do |filter, options|
24
+ @_registered_filters[filter] ||= { attributes: Set.new, options: options }
25
+ @_registered_filters[filter][:attributes].merge(attrs)
26
26
  end
27
27
  end
28
28
 
@@ -3,11 +3,11 @@
3
3
  module AttrFilters
4
4
  module InstanceMethods
5
5
  def filter!
6
- self.class._registered_filters.each_pair do |filter_name, attrs|
6
+ self.class._registered_filters.each_pair do |filter_name, params|
7
7
  filter = build_filter(filter_name)
8
- attrs.each do |attr|
8
+ params[:attributes].each do |attr|
9
9
  value = send(attr)
10
- send("#{attr}=", filter.call(value))
10
+ send("#{attr}=", filter.call(value, params[:options]))
11
11
  end
12
12
  end
13
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AttrFilters
4
- VERSION = "0.3.2"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attr_filters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Holovko
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-10-28 00:00:00.000000000 Z
12
+ date: 2019-11-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -113,6 +113,7 @@ files:
113
113
  - lib/attr_filters/filters.rb
114
114
  - lib/attr_filters/filters/base.rb
115
115
  - lib/attr_filters/filters/capitalize.rb
116
+ - lib/attr_filters/filters/date.rb
116
117
  - lib/attr_filters/filters/downcase.rb
117
118
  - lib/attr_filters/filters/letters_only.rb
118
119
  - lib/attr_filters/filters/numbers_only.rb
@@ -145,8 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
146
  - !ruby/object:Gem::Version
146
147
  version: '0'
147
148
  requirements: []
148
- rubyforge_project:
149
- rubygems_version: 2.7.6
149
+ rubygems_version: 3.0.3
150
150
  signing_key:
151
151
  specification_version: 4
152
152
  summary: Light weight gem for filtering PORO (Plain Old Ruby Objects) attributes with