spaghetti_squash 0.0.1

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: 69a38f730947bbd8abe3fef6c238a530ad6b7a66
4
+ data.tar.gz: 754657b9b4c8aef7b55cb91259ff797337bae04b
5
+ SHA512:
6
+ metadata.gz: d21a62a418104e91ebf29099f785f080fbfae345c9719ace7be0b30a29880b566faf7af372ef474c12691a1ecc14759b9c669fed849ee615542edaa98417f6db
7
+ data.tar.gz: a4bc255a65150cf5d1052ce015d8a28d69c5588c8c9b52af0c2bc9324d8858f7a0faa330a071870f740d8c44b3332f01b2355bc61f9ca67e31af9031bb00b1c4
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in spaghetti_squash.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # SpaghettiSquash
2
+
3
+ SpagettiSquash is the story of me making better an app with page after page of interlinked ActiveRecord callbacks triggering them.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'spaghetti_squash', group: :development
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install spaghetti_squash
18
+
19
+ ## Usage
20
+
21
+ Right now, all it does it log the beginning and end of all they callbacks, so you can see what's going on.
22
+
23
+ For example
24
+
25
+ ````
26
+ % rails c ✹
27
+ Loading development environment (Rails 4.1.4)
28
+ (development on MarketMaker) irb(main):001:0> User.last.save
29
+ User Load (18.0ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
30
+ (0.8ms) BEGIN
31
+ User Exists (14.5ms) SELECT 1 AS one FROM "users" WHERE ("users"."email" = 'example@example.com' AND "users"."id" != 1) LIMIT 1
32
+ starting callback: save [:standardize_for_search] {}
33
+ finishing callback
34
+ (0.3ms) COMMIT
35
+ => true
36
+ (development on MarketMaker) irb(main):002:0>
37
+
38
+ ````
39
+
40
+ It should only log callbacks that originate from your code, but this might break if you vendor gems or your Rails.root is somewhere strange.
41
+
42
+ It probably slows down your app a lot.
43
+
44
+ ## Requirements
45
+
46
+ I'm developing this against Rails 4.1, but I'd accept bugs against any Rails 4 version.
47
+
48
+ ## In the future
49
+
50
+ Printing out a tree structure, and counting call backs per-request (or save, or something).
51
+
52
+ Some tools to help you pull callbacks into seperate objects that can, one hopes, be refactored away.
53
+
54
+ Who knows.
55
+
56
+ ## Contributing
57
+
58
+ 1. Fork it ( https://github.com/[my-github-username]/spaghetti_squash/fork )
59
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
60
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
61
+ 4. Push to the branch (`git push origin my-new-feature`)
62
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,48 @@
1
+ require "spaghetti_squash/version"
2
+
3
+ module SpaghettiSquash
4
+ module Patch
5
+ module ClassMethods
6
+ def set_callback(name, *filter_list, &block)
7
+ super name, *filter_list do
8
+ type, filters, options = self.class.normalize_callback_params(filter_list, block)
9
+ if in_app?(filters.first)
10
+ ActiveRecord::Base.logger.info "starting callback: #{name} #{filters} #{options}"
11
+ end
12
+ end
13
+ super
14
+ super name, *filter_list do
15
+ type, filters, options = self.class.normalize_callback_params(filter_list, block)
16
+ if in_app?(filters.first)
17
+ Rails.logger.info "finishing callback"
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ def in_app?(proc_or_symbol)
24
+ if proc_or_symbol.respond_to?(:source_location)
25
+ path = proc_or_symbol.source_location.first
26
+ elsif proc_or_symbol.is_a?(Symbol)
27
+ path = self.method(proc_or_symbol).source_location.first
28
+ else
29
+ path = ''
30
+ end
31
+
32
+ path = Pathname.new path
33
+
34
+ in_app = false
35
+ path.ascend {|p| in_app = true if p === Rails.root}
36
+ in_app
37
+ end
38
+
39
+ def self.prepended(base)
40
+ base.singleton_class.send :prepend, ClassMethods
41
+ end
42
+ end
43
+ class Railtie < Rails::Railtie
44
+ ActiveSupport.on_load :active_record do
45
+ ActiveRecord::Base.send :prepend, SpaghettiSquash::Patch
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ module SpaghettiSquash
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spaghetti_squash/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "spaghetti_squash"
8
+ spec.version = SpaghettiSquash::VERSION
9
+ spec.authors = ["Micah Gates"]
10
+ spec.email = ["gems@mgates.com"]
11
+ spec.summary = %q{Squash Your Callback Spaghetti}
12
+ spec.homepage = "https://github.com/mgates/spaghetti_squash"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake"
22
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spaghetti_squash
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Micah Gates
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - gems@mgates.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/spaghetti_squash.rb
54
+ - lib/spaghetti_squash/version.rb
55
+ - spaghetti_squash.gemspec
56
+ homepage: https://github.com/mgates/spaghetti_squash
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.2.2
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Squash Your Callback Spaghetti
80
+ test_files: []
81
+ has_rdoc: