nullify-attr 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
+ SHA1:
3
+ metadata.gz: 1ad857a1b7352bdcaf6582652109a3208b9a6067
4
+ data.tar.gz: 5da89fd07756849314c52fd418a5afd2e8914937
5
+ SHA512:
6
+ metadata.gz: ee131bc75aef15e0bb6ef4e4b3beca5359fea18050aedd89e14b203b44b80de45040b109fee9532b7031058427967cae3b195d2c5346f0541b7698fc0a2374ba
7
+ data.tar.gz: a8546b9d5c8363fcbb0bcf8be3218ff1d719794e88943e8a99668358861fc4b3169827c4680c3727d30f06f5fd93d8e252e2aed895a301fdb295e03d3b3d2c09
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ .ruby-version
4
+ pkg/
5
+ tmp/
6
+ /.idea/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ source 'https://rubygems.org'
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nullify-attr (1.0.0)
5
+ activerecord (>= 3.0, < 6.0)
6
+ activesupport (>= 3.0, < 6.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (5.0.2)
12
+ activesupport (= 5.0.2)
13
+ activerecord (5.0.2)
14
+ activemodel (= 5.0.2)
15
+ activesupport (= 5.0.2)
16
+ arel (~> 7.0)
17
+ activesupport (5.0.2)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ i18n (~> 0.7)
20
+ minitest (~> 5.1)
21
+ tzinfo (~> 1.1)
22
+ arel (7.1.4)
23
+ concurrent-ruby (1.0.5)
24
+ i18n (0.8.1)
25
+ minitest (5.10.1)
26
+ thread_safe (0.3.6)
27
+ tzinfo (1.2.2)
28
+ thread_safe (~> 0.1)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ nullify-attr!
35
+
36
+ BUNDLED WITH
37
+ 1.14.3
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ ## Conditionally nullify attributes.
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/nullify-attr.svg)](https://badge.fury.io/rb/nullify-attr)
4
+
5
+ ## About
6
+ Allows to conditionally (support both `if` and `unless`.) nullify attributes in `before_validation` hook.
7
+
8
+ ## Usage
9
+ ```ruby
10
+ class Post < ActiveRecord::Base
11
+ # Store description as NULL when description is blank.
12
+ nullify :description, unless: :description?
13
+ end
14
+
15
+ class Payment < ActiveRecord::Base
16
+ # We don't want to store bank card vendor when payment method isn't bank card.
17
+ nullify :bank_card_vendor, unless: :paid_using_bank_card?
18
+ end
19
+ ```
20
+
21
+ ## Installing gem
22
+ Add to your Gemfile:
23
+ ```ruby
24
+ gem 'nullify-attr', '~> 1.0'
25
+ ```
@@ -0,0 +1,33 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'active_support/concern'
5
+ require 'active_support/lazy_load_hooks'
6
+
7
+ module NullifyAttr
8
+ module Extension
9
+ extend ActiveSupport::Concern
10
+
11
+ module ClassMethods
12
+ def nullify(*attributes)
13
+ before_validation attributes.extract_options! do
14
+ attributes.each do |attribute|
15
+ case attribute
16
+ when Regexp
17
+ self.class.column_names.each do |column_name|
18
+ if column_name.respond_to?(:match?) ? column_name.match?(attribute) : column_name =~ attribute
19
+ send("#{column_name}=", nil)
20
+ end
21
+ end
22
+ else
23
+ send("#{attribute}=", nil)
24
+ end
25
+ end
26
+ nil
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ ActiveSupport.on_load(:active_record) { ActiveRecord::Base.include NullifyAttr::Extension }
@@ -0,0 +1,6 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ module NullifyAttr
5
+ VERSION = '1.0.0'
6
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ require File.expand_path('../lib/nullify-attr/version', __FILE__)
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'nullify-attr'
8
+ s.version = NullifyAttr::VERSION
9
+ s.author = 'Yaroslav Konoplov'
10
+ s.email = 'eahome00@gmail.com'
11
+ s.summary = 'Conditionally nullify attributes.'
12
+ s.description = 'Conditionally nullify attributes.'
13
+ s.homepage = 'https://github.com/yivo/nullify-attr'
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files -z`.split("\x0")
17
+ s.test_files = `git ls-files -z -- {test,spec,features}/*`.split("\x0")
18
+ s.require_paths = ['lib']
19
+
20
+ s.add_dependency 'activesupport', '>= 3.0', '< 6.0'
21
+ s.add_dependency 'activerecord', '>= 3.0', '< 6.0'
22
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nullify-attr
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Yaroslav Konoplov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: activerecord
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '3.0'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '6.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '3.0'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '6.0'
53
+ description: Conditionally nullify attributes.
54
+ email: eahome00@gmail.com
55
+ executables: []
56
+ extensions: []
57
+ extra_rdoc_files: []
58
+ files:
59
+ - ".gitignore"
60
+ - Gemfile
61
+ - Gemfile.lock
62
+ - README.md
63
+ - lib/nullify-attr.rb
64
+ - lib/nullify-attr/version.rb
65
+ - nullify-attr.gemspec
66
+ homepage: https://github.com/yivo/nullify-attr
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.6.8
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Conditionally nullify attributes.
90
+ test_files: []