attr_sanitizable 0.0.3 → 1.0.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
- SHA1:
3
- metadata.gz: d230cec7b7b9da32a0d5e55737d7f05ede053e14
4
- data.tar.gz: 685a472e9dcd4d6ab93d7658638b2765a14f352d
2
+ SHA256:
3
+ metadata.gz: 672ebee591f6eb296af457122638af29f7d1cb8c2c2981f054599fd068f90375
4
+ data.tar.gz: e5bbd207421279904ed49c93fbda029ee93c6009cc09a82ce20d9d33b8e5031a
5
5
  SHA512:
6
- metadata.gz: eda4a462d12b9ed42124477b330e0ac34d5dc47b5f38f10ccc3cd3f65fec4f121436b55bbea7e38eef3a5aa4b4fb66aa6317d684d7cc8e67d98a664bde9b5a5f
7
- data.tar.gz: 98525255b6da562935e1f93aeefa44d955f79dcd9438f59d9ce0438ed602f23a39f528b9fe0a3e394ab55903950aaea174006cc7b4f8e7b14c811e8fab2b966d
6
+ metadata.gz: 00657d359383b2db5be824bd0c76bfafaa5fba81954ed9c5fcb5af783a2a5ba91fd19e7114b38b2caf71a74d6d203dcea2ee8176addae013afba77173bed9819
7
+ data.tar.gz: c76b4734a80ae611a2bf9feaac9d64d36e635a76751271475abd3b25722cd9f0a63b3cb1b227bbc1e98bafbaad925ea53e1fedf4df821c1b83150947377c83e1
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 1.0.0
2
+
3
+ - Added the ability to send functions with parameters to attributes
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Aaron Price
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # attr_sanitizable
2
+
3
+ ### Description
4
+
5
+ A gem for sanitizing data into your database.
6
+
7
+ ### Install
8
+
9
+ The best way to install is to add it to your Gemfile via:
10
+ ```
11
+ gem 'attr_sanitizable'
12
+ ```
13
+
14
+ ### Usage
15
+
16
+ ```ruby
17
+ class MyModel < ActiveRecord::Base
18
+ attr_sanitizable :email, with: [:strip, :downcase]
19
+
20
+ # Send actions that have params as follows
21
+ attr_sanitizable :phone, with: [[:scan, /\d/], :join, [:sub, /^1/, '']]
22
+ end
23
+
24
+ m = MyModel.new
25
+ m.email = " NOBODY@EXAMPLE.COM\n"
26
+ # => "nobody@example.com"
27
+ ```
28
+
29
+ ### Custom Sanitizers
30
+
31
+ ```ruby
32
+ class String
33
+ def troll
34
+ self.gsub(/a/, "@")
35
+ end
36
+ end
37
+
38
+ class User < ActiveRecord::Base
39
+ attr_sanitizable :email, with: [:troll]
40
+ end
41
+
42
+ user = User.new
43
+ user.email = "nobody@example.com"
44
+ # => "nobody@ex@mple.com"
45
+ ```
46
+
47
+ ### Contributing
48
+
49
+ Feel free to contribute features or bug fixes. Simply fork the repo, implement your feature/bugfix, and submit a pull request. Please ensure you've properly tested your feature/fix before submitting a pull request.
50
+
51
+
52
+ ### License
53
+
54
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
55
+
56
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
57
+
58
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+ require 'attr_sanitizable/version'
3
+
1
4
  module AttrSanitizable
2
5
 
3
6
  def self.included(base)
@@ -13,14 +16,13 @@ module AttrSanitizable
13
16
 
14
17
  attributes.each do |field|
15
18
  define_method "#{field}=" do |value|
16
- if !value.nil?
17
- actions.each do |action|
18
- if !value.respond_to?(action)
19
- raise ArgumentError, "Unable to perform '#{action}' on a variable of type '#{value.class.name}'"
20
- end
21
- value = value.try(action)
22
- end
19
+ return if value.nil?
20
+
21
+ actions.compact.each do |action|
22
+ raise ArgumentError, "Unable to perform '#{action}' on a variable of type '#{value.class.name}'" unless value.respond_to?([*action].first)
23
+ value = value.send(*[*action])
23
24
  end
25
+
24
26
  write_attribute(field, value)
25
27
  end
26
28
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AttrSanitizable
4
+ VERSION = '1.0.0'
5
+ end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attr_sanitizable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Price
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2014-10-28 00:00:00.000000000 Z
@@ -53,19 +53,25 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: rspec-rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.0'
61
+ version: '3.3'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 3.3.3
62
65
  type: :development
63
66
  prerelease: false
64
67
  version_requirements: !ruby/object:Gem::Requirement
65
68
  requirements:
66
69
  - - "~>"
67
70
  - !ruby/object:Gem::Version
68
- version: '2.0'
71
+ version: '3.3'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 3.3.3
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: rake
71
77
  requirement: !ruby/object:Gem::Requirement
@@ -86,18 +92,25 @@ dependencies:
86
92
  - - ">="
87
93
  - !ruby/object:Gem::Version
88
94
  version: '0.9'
89
- description: Active Record extention to sanitize your inputs.
95
+ description: Active Record extention to sanitize your inputspec.
90
96
  email: price.aaron@gmail.com
91
97
  executables: []
92
98
  extensions: []
93
99
  extra_rdoc_files: []
94
100
  files:
101
+ - CHANGELOG.md
102
+ - LICENSE
103
+ - README.md
95
104
  - lib/attr_sanitizable.rb
105
+ - lib/attr_sanitizable/version.rb
96
106
  homepage: https://github.com/aaronprice/attr_sanitizable
97
107
  licenses:
98
108
  - MIT
99
- metadata: {}
100
- post_install_message:
109
+ metadata:
110
+ homepage_uri: https://github.com/aaronprice/attr_sanitizable
111
+ source_code_uri: https://github.com/aaronprice/attr_sanitizable
112
+ changelog_uri: https://github.com/aaronprice/attr_sanitizable/blob/main/CHANGELOG.md
113
+ post_install_message:
101
114
  rdoc_options: []
102
115
  require_paths:
103
116
  - lib
@@ -105,16 +118,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
118
  requirements:
106
119
  - - ">="
107
120
  - !ruby/object:Gem::Version
108
- version: '0'
121
+ version: 2.3.0
109
122
  required_rubygems_version: !ruby/object:Gem::Requirement
110
123
  requirements:
111
124
  - - ">="
112
125
  - !ruby/object:Gem::Version
113
126
  version: '0'
114
127
  requirements: []
115
- rubyforge_project:
116
- rubygems_version: 2.4.5.1
117
- signing_key:
128
+ rubygems_version: 3.2.3
129
+ signing_key:
118
130
  specification_version: 4
119
- summary: Active Record extention to sanitize your inputs.
131
+ summary: Active Record extention to sanitize your inputspec.
120
132
  test_files: []