cleaning_cloth 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 305ff895580fa9c8aa82b898c81e8647f97d45fd
4
+ data.tar.gz: 8d70cea1bc8a3fbb237e88ee25697e4bd6ec760d
5
+ SHA512:
6
+ metadata.gz: 6221df7c8300d0791bc2ff54c1429e2e77783cb86caae0ee7365a3f371c6324d65562df9d35380b05514a425f2af0fca3d8e1d954078a98f0f2a1d29523cd4d1
7
+ data.tar.gz: c447aa69abc21811d8bafecb355618f03f17bcfcf91e3b16b0714f64c40641eca5cdfcc5c60ac4a76e86b4154ab5fb91bba355c13397888f416d2c00cec5022d
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = CleaningCloth2
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'CleaningCloth2'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ require 'rake/testtask'
23
+
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+
32
+ task default: :test
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+ require 'active_record'
3
+
4
+ class ActiveRecord::Base
5
+
6
+ unless self.method_defined? 'clean!'
7
+
8
+ def clean! opts=nil
9
+
10
+ opts ||= default_clean_options
11
+ opts[:max_level] ||= 3
12
+ return if opts[:max_level] <= 0
13
+
14
+ exceptions = Array(opts[:except] || []) + [:id, :create_at, :updated_at]
15
+ includes = Array(opts[:includes] || []) # includes, caso queira incluir os campos excluidos por padrão: :id, :created_at e etc
16
+ exceptions.reject! {|item| includes.include?(item) }
17
+
18
+ all_attributes = self.attributes || {}
19
+
20
+ all_associations = self.class.reflect_on_all_associations.map &:name
21
+ all_associations.reject! {|item| exceptions.include?(item)}
22
+
23
+ all_associations.each do |assoc_name|
24
+ data = self.send(assoc_name)
25
+ next unless data.present?
26
+ Array(data).each do |obj|
27
+ obj_opts = opts.deep_fetch(assoc_name, {})
28
+ obj_opts[:max_level] = opts[:max_level] - 1
29
+ obj.clean! obj_opts
30
+ end
31
+ end
32
+
33
+ all_attributes.each do |attr_name, attr_value|
34
+ attr_name = attr_name.to_sym
35
+ next if exceptions.include?(attr_name) && attr_value == self.send(attr_name)
36
+ value = exceptions.include?(attr_name) ? attr_value : nil
37
+ self.send("write_attribute", attr_name, value)
38
+ end
39
+
40
+ self
41
+
42
+ end # clean!
43
+
44
+ def default_clean_options
45
+ {}
46
+ end
47
+
48
+ end
49
+ end
50
+
51
+
@@ -0,0 +1,3 @@
1
+ module CleaningCloth
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,6 @@
1
+ #byebug
2
+ # require File.expand_path("../lib/cleaning_cloth/active_record_extension.rb", __FILE__)
3
+ require "cleaning_cloth/active_record_extension"
4
+ require 'ds_hash'
5
+ module CleaningCloth
6
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :cleaning_cloth2 do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cleaning_cloth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - nardele salomon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-16 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.2'
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '4.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '4.1'
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.2'
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '4.1'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.2'
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '4.1'
53
+ - !ruby/object:Gem::Dependency
54
+ name: ds_hash
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1'
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '1'
67
+ - !ruby/object:Gem::Dependency
68
+ name: sqlite3
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '1.3'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '1.3'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rspec-rails
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '3.1'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '3.1'
95
+ - !ruby/object:Gem::Dependency
96
+ name: factory_girl
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '4.4'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '4.4'
109
+ description: An simple way to clear atrributes in active record
110
+ email:
111
+ - del.soft.99@gmail.com
112
+ executables: []
113
+ extensions: []
114
+ extra_rdoc_files: []
115
+ files:
116
+ - MIT-LICENSE
117
+ - README.rdoc
118
+ - Rakefile
119
+ - lib/cleaning_cloth.rb
120
+ - lib/cleaning_cloth/active_record_extension.rb
121
+ - lib/cleaning_cloth/version.rb
122
+ - lib/tasks/cleaning_cloth_tasks.rake
123
+ homepage: https://github.com/telelistas/cleaning-cloth
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.2.2
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: An Rails/Active Record extension. You will clean all atributes of active
147
+ record
148
+ test_files: []