who_comes_first 0.0.0

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 (2) hide show
  1. data/lib/who_comes_first.rb +35 -0
  2. metadata +46 -0
@@ -0,0 +1,35 @@
1
+ class WhoComesFirst
2
+
3
+ def self.who_comes_first(model,methods = [],operation = :create)
4
+ callbacks_name_list = [:before_validation,
5
+ "before_validation_on_#{operation}".to_sym,
6
+ :after_validation,
7
+ "after_validation_on_#{operation}".to_sym,
8
+ :before_save,
9
+ "before_#{operation}".to_sym,
10
+ "after_#{operation}".to_sym,
11
+ :after_save,
12
+ "before_commit_on_#{operation}".to_sym,
13
+ "after_commit_on_#{operation}".to_sym
14
+ ]
15
+ callbacks_name_list.each { |callback_name| model.send(callback_name).each { |cb| process_callback(cb,methods)}}
16
+ end
17
+
18
+ def self.process_callback(cb,methods)
19
+ unless cb.method.to_s =~ /before_save_collection_association|autosave_associated_records/i
20
+ print_array = []
21
+ methods_array = []
22
+ options_array = []
23
+ kind_array = []
24
+
25
+ methods_array << cb.method.to_sym
26
+ options_array << (cb.options.empty? ? nil : cb.options)
27
+ kind_array << (cb.kind.empty? ? nil : cb.kind)
28
+
29
+ methods_array = methods_array & methods unless methods.empty?
30
+
31
+ print_array << [methods_array + options_array + kind_array]
32
+ pp print_array.flatten.compact unless methods_array.empty?
33
+ end
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: who_comes_first
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Srinivasan C
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-06-13 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Who Comes First
15
+ email: karthickpdy@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/who_comes_first.rb
21
+ homepage:
22
+ licenses:
23
+ - MIT
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 1.8.30
43
+ signing_key:
44
+ specification_version: 3
45
+ summary: Gem To know the order of callbacks in a specified model
46
+ test_files: []