silent-fail-check 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.
Files changed (3) hide show
  1. checksums.yaml +15 -0
  2. data/lib/silent_fail_check.rb +47 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZWE3NjVjNTYzOTk2N2I0Zjk3MTc1YzVkM2ZhY2Q0NWIwZDUyMmEyMQ==
5
+ data.tar.gz: !binary |-
6
+ Zjg2YTg2MDEwYzgwNzc2NzI0ZTlkZTZjOGQ2NDY1ZmJkZGZiMmUzZQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YmNmZTUzYjgzMDFlODZhMzA3ODhkZmRjNTI5MGE0NzcwMjQ4NjE0MTBlYmYz
10
+ ZWEyZmNlMThmYzk2MzFhOTUzNmQxNmZlZGVjZTkxZDdlODdlMTIwMmVlMmZl
11
+ ZjVjZDFlYTZkMzNkOTZkZDMzZGJlMjYzOWE3NmVlNDI5YTFmZGU=
12
+ data.tar.gz: !binary |-
13
+ MThkNjQzMDkyNzAxMWQyOWEyNmM3ZjkyMGRjMTE0ZDQ1ZjJiYjQ2NzA3NWFl
14
+ MzIyMmQwZDczMDRhOTcwMmJhYzFjYTU5NDJlZGMzOTY0NWJmNTE1YjZhOWI2
15
+ NmM0YWMwMGQ3OTczOGJhMjZiNDQxZTcxYTE0NmQ3YjRjMGZhNDY=
@@ -0,0 +1,47 @@
1
+ class SilentFailCheck
2
+ module Models
3
+ CheckParameters = Struct.new(:sym, :args, :block)
4
+
5
+ def silent_fail_check sym, *args, &block
6
+ extend ClassMethods
7
+ include InstanceMethods
8
+
9
+ @check_parameters = CheckParameters.new(sym, args, block)
10
+
11
+ method_name = "add_#{sym}_fail_check"
12
+ send(method_name) if respond_to?(method_name, true)
13
+ end
14
+
15
+ module ClassMethods
16
+
17
+ private
18
+
19
+ def check_parameters
20
+ @check_parameters
21
+ end
22
+
23
+ def add_validation_fail_check
24
+ after_validation "#{check_parameters.sym}_fail_check"
25
+ end
26
+ end
27
+
28
+ module InstanceMethods
29
+
30
+ private
31
+
32
+ def validation_fail_check
33
+ p = self.class.send(:check_parameters)
34
+
35
+ if p.block.nil?
36
+ p.args.each do |a|
37
+ puts "#{self.class} : #{a} #{self.errors[a]}" if self.errors[a].present?
38
+ end
39
+ else
40
+ p.args.collect &p.block
41
+ end
42
+ end
43
+
44
+ end
45
+ end
46
+ ActiveRecord::Base.extend Models
47
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: silent-fail-check
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adrien Folie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Handle silent failure on ActiveRecord::Base
14
+ email: folie.adrien@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/silent_fail_check.rb
20
+ homepage: http://rubygems.org/gems/silent-fail-check
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.2.2
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: silent-fail-check
44
+ test_files: []