union_station_hooks_rails 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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDBmNjQ1YWNkZDdjZjAwOTMzZWQ1NjEyZDBiOGZjYWJhMWYzMmM5Zg==
5
+ data.tar.gz: !binary |-
6
+ NDEyNzgzMWJjMjdiMWFhNTkyMjUyZWQxNWY1Mzg4NGYwZDgzODE4OA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NDYzNzBiZjk4MmZhY2JhYmJkNGJjM2JiNWZjNWU5NTRkYjRiNmE5ZGY2ZmQw
10
+ YmI3YzRhM2YxNzBjZWYzNWVhZmUwNjYzNDUxMTUzOGQ1MTQwMTY0OTI1ZjVj
11
+ YTVkMWM4N2IzMTdlOGMzN2UzNjI1NmRjOTBiYzZlZGM1NDlhNmY=
12
+ data.tar.gz: !binary |-
13
+ MWQ2YzQ2ZWJkNWRiNTRmZDQ1NzE5NjFhZDk5YzRjNTZhMzNkODMwZGM3MzZl
14
+ NDA0M2NiYzUyOGU2M2QxNGNkZGFhYmNkYzdmOTExNDY2MTBiZTJiMjFmNzgz
15
+ MjI3MTM3OTA4MjlkMzFlOGUzODExMGQ0MGQ4ZTMyYjNjMjYxMGE=
data/LICENSE.md ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010-2015 Phusion Holding B.V.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # Union Station Ruby hooks core
2
+
3
+ [![Build Status](https://travis-ci.org/phusion/union_station_hooks_rails.svg?branch=master)](https://travis-ci.org/phusion/union_station_hooks_rails)
4
+
5
+ [Union Station](https://www.unionstationapp.com) is a web application monitoring and performance analytics platform for Ruby. In order for Union Station to analyze your application, your application must send data to Union Station. This gem allows you to do that.
6
+
7
+ `union_station_hooks_rails` is a gem that automatically hooks into various parts of Rails, so that the right information is sent to Union Station. Under the hood, it makes use of the APIs provided by [union_station_hooks_core](https://github.com/phusion/union_station_hooks_core).
8
+
9
+ **Resources:** [About Union Station](https://www.unionstationapp.com) | [Github](https://github.com/phusion/union_station_hooks_rails)
10
+
11
+ **Table of contents**
12
+
13
+ * [Installation](#installation)
14
+ - [Using with Passenger](#using-with-passenger)
15
+ - [Overriding Passenger's version](#overriding-passengers-version)
16
+ - [Using without Passenger](#using-without-passenger)
17
+ * [Legacy code](#legacy-code)
18
+ * [Contributing](contributing)
19
+
20
+ ---
21
+
22
+ ## Installation
23
+
24
+ ### Using with Passenger
25
+
26
+ **Note: This documentation section only applies to Passenger X.X.X or later!**
27
+
28
+ If you use [Passenger](https://www.phusionpassenger.com/), then you do not need to install the `union_station_hooks_rails` gem. `union_station_hooks_rails` is bundled with Passenger.
29
+
30
+ The only thing you need to do is to create a file `config/initializers/union_station.rb` in which you call this code:
31
+
32
+ if defined?(UnionStationHooks)
33
+ UnionStationHooks.initialize!
34
+ end
35
+
36
+ (Are you already calling `PhusionPassenger.install_framework_extensions!` from somewhere in your codebase? Please read [Legacy code](#legacy-code) for important information.)
37
+
38
+ When you have this call in place, enable Union Station support in Passenger. Here are some examples:
39
+
40
+ * _Passenger with Nginx integration mode_<br>
41
+
42
+ Insert the following config in your virtual host configuration, then restart Nginx:
43
+
44
+ union_station_support on;
45
+ union_station_key <YOUR KEY HERE>;
46
+
47
+ * _Passenger with Apache integration mode_<br>
48
+
49
+ Insert the following config in your virtual host configuration, then restart Apache:
50
+
51
+ UnionStationSupport on
52
+ UnionStationKey <YOUR KEY HERE>
53
+
54
+ * _Passenger Standalone_<br>
55
+
56
+ Start Passenger with the `--union-station-key` parameter:
57
+
58
+ $ passenger start --union-station-key <YOUR KEY HERE>
59
+
60
+ Or set the `union_station_key` configuration option in Passengerfile.json:
61
+
62
+ {
63
+ "union_station_key": "<YOUR KEY HERE>"
64
+ }
65
+
66
+ ### Overriding Passenger's version
67
+
68
+ Each version of Passenger bundles its own version of the `union_station_hooks_rails` gem (and the `union_station_hooks_core` gem, which is a dependency). The Passenger maintainers regularly update their bundled versions with the latest version. Sometimes, you may wish to use a specific version of `union_station_hooks_rails` and `union_station_hooks_core`, overriding the versions that came bundled with Passenger. For example, we have may published a new version of `union_station_hooks_rails` with some bug fixes, even though Passenger hasn't been updated yet.
69
+
70
+ You can override Passenger's bundled versions as follows.
71
+
72
+ 1. Add the gems you want to override to your Gemfile, like this:
73
+
74
+ # Uncomment the following line if you want to override Passenger's
75
+ # bundled version
76
+ #gem 'union_station_hooks_core'
77
+
78
+ gem 'union_station_hooks_rails'
79
+
80
+ 2. Install your gem bundle:
81
+
82
+ bundle install
83
+
84
+ ### Using without Passenger
85
+
86
+ It is currently not possible to use Union Station without Passenger. If you would like to have this feature, please let us know.
87
+
88
+ ## Legacy code
89
+
90
+ Before Passenger X.X.X, the Union Station setup instructions used to tell you to create a `config/initializers/passenger.rb` in which you call the following code:
91
+
92
+ PhusionPassenger.install_framework_extensions! if defined?(PhusionPassenger)
93
+
94
+ Since Passenger X.X.X, `PhusionPassenger.install_framework_extensions!` has become an alias for `UnionStationHooks.initialize!`, but the former is considered deprecated. Please replace the above code with:
95
+
96
+ if defined?(UnionStationHooks)
97
+ UnionStationHooks.initialize!
98
+ end
99
+
100
+ And please also rename `config/initializers/passenger.rb` to `config/initializers/union_station.rb`.
101
+
102
+ ## Contributing
103
+
104
+ Looking to contribute to this gem? Please read the documentation in the [hacking/](https://github.com/phusion/union_station_hooks_rails/blob/master/hacking) directory.
@@ -0,0 +1,54 @@
1
+ # Union Station - https://www.unionstationapp.com/
2
+ # Copyright (c) 2010-2015 Phusion Holding B.V.
3
+ #
4
+ # "Union Station" and "Passenger" are trademarks of Phusion Holding B.V.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+
24
+
25
+ module UnionStationHooksRails
26
+ module ActionControllerExtension
27
+ def process_action(action, *args)
28
+ reporter = request.env['union_station_hooks']
29
+ return super if !reporter
30
+
31
+ options = {
32
+ :controller_name => self.class.name,
33
+ :action_name => action_name,
34
+ :method => request.request_method
35
+ }
36
+ reporter.log_controller_action_block(options) do
37
+ super
38
+ end
39
+ end
40
+
41
+ def render(*args)
42
+ reporter = request.env['union_station_hooks']
43
+ return super if !reporter
44
+
45
+ reporter.log_view_rendering_block do
46
+ super
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ ActionController::Base.class_eval do
53
+ include UnionStationHooksRails::ActionControllerExtension
54
+ end
@@ -0,0 +1,41 @@
1
+ # Union Station - https://www.unionstationapp.com/
2
+ # Copyright (c) 2010-2015 Phusion Holding B.V.
3
+ #
4
+ # "Union Station" and "Passenger" are trademarks of Phusion Holding B.V.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+
24
+
25
+ module UnionStationHooksRails
26
+ class ActiveRecordSubscriber < ActiveSupport::LogSubscriber
27
+ def sql(event)
28
+ reporter = Thread.current[:union_station_hooks]
29
+ return if !reporter
30
+
31
+ UnionStationHooks.call_event_pre_hook(event)
32
+ reporter.log_database_query(
33
+ :begin_time => event.time,
34
+ :end_time => event.time,
35
+ :query => event.payload[:sql]
36
+ )
37
+ end
38
+ end
39
+ end
40
+
41
+ UnionStationHooksRails::ActiveRecordSubscriber.attach_to(:active_record)
@@ -0,0 +1,47 @@
1
+ # Union Station - https://www.unionstationapp.com/
2
+ # Copyright (c) 2010-2015 Phusion Holding B.V.
3
+ #
4
+ # "Union Station" and "Passenger" are trademarks of Phusion Holding B.V.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+
24
+
25
+ module UnionStationHooksRails
26
+ module ActiveSupportBenchmarkableExtension
27
+ def benchmark_with_union_station(message = 'Benchmarking', *args)
28
+ reporter = Thread.current[:union_station_hooks]
29
+ if reporter
30
+ reporter.log_benchmark_block(message) do
31
+ benchmark_without_union_station(message, *args) do
32
+ yield
33
+ end
34
+ end
35
+ else
36
+ benchmark_without_union_station(message, *args) do
37
+ yield
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ ActiveSupport::Benchmarkable.class_eval do
45
+ include UnionStationHooksRails::ActiveSupportBenchmarkableExtension
46
+ alias_method_chain :benchmark, :union_station
47
+ end
@@ -0,0 +1,70 @@
1
+ # Union Station - https://www.unionstationapp.com/
2
+ # Copyright (c) 2010-2015 Phusion Holding B.V.
3
+ #
4
+ # "Union Station" and "Passenger" are trademarks of Phusion Holding B.V.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+
24
+
25
+ module UnionStationHooksRails
26
+ class ActiveSupportCacheSubscriber < ActiveSupport::LogSubscriber
27
+ def cache_read(event)
28
+ reporter = Thread.current[:union_station_hooks]
29
+ return if !reporter
30
+
31
+ UnionStationHooks.call_event_pre_hook(event)
32
+ if event.payload[:hit]
33
+ reporter.log_cache_hit(event.payload[:key])
34
+ else
35
+ reporter.log_cache_miss(event.payload[:key])
36
+ end
37
+ end
38
+
39
+ def cache_fetch_hit(event)
40
+ reporter = Thread.current[:union_station_hooks]
41
+ return if !reporter
42
+
43
+ UnionStationHooks.call_event_pre_hook(event)
44
+ reporter.log_cache_hit(event.payload[:key])
45
+ end
46
+
47
+ def cache_generate(event)
48
+ reporter = Thread.current[:union_station_hooks]
49
+ return if !reporter
50
+
51
+ UnionStationHooks.call_event_pre_hook(event)
52
+ reporter.log_cache_miss(event.payload[:key],
53
+ (event.duration * 1_000_000).to_i)
54
+ end
55
+ end
56
+ end
57
+
58
+ ActiveSupport::Cache::Store.instrument = true
59
+
60
+ if defined?(PhusionPassenger)
61
+ PhusionPassenger.on_event(:starting_request_handler_thread) do
62
+ if defined?(ActiveSupport::Cache::Store)
63
+ # This flag is thread-local, so re-initialize it for every
64
+ # request handler thread.
65
+ ActiveSupport::Cache::Store.instrument = true
66
+ end
67
+ end
68
+ end
69
+
70
+ UnionStationHooksRails::ActiveSupportCacheSubscriber.attach_to(:active_support)
@@ -0,0 +1,57 @@
1
+ # Union Station - https://www.unionstationapp.com/
2
+ # Copyright (c) 2010-2015 Phusion Holding B.V.
3
+ #
4
+ # "Union Station" and "Passenger" are trademarks of Phusion Holding B.V.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+
24
+
25
+ module UnionStationHooksRails
26
+ class ExceptionLogger
27
+ def initialize(app)
28
+ @app = app
29
+ end
30
+
31
+ def call(env)
32
+ @app.call(env)
33
+ rescue Exception => e
34
+ report_exception(env, e)
35
+ raise e
36
+ end
37
+
38
+ private
39
+ def report_exception(env, exception)
40
+ reporter = env['union_station_hooks']
41
+ if reporter
42
+ reporter.log_exception(exception)
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ if defined?(ActionDispatch::DebugExceptions)
49
+ exceptions_middleware = ActionDispatch::DebugExceptions
50
+ elsif defined?(ActionDispatch::ShowExceptions)
51
+ exceptions_middleware = ActionDispatch::ShowExceptions
52
+ end
53
+ if exceptions_middleware && defined?(Rails)
54
+ Rails.application.middleware.insert_after(
55
+ exceptions_middleware,
56
+ UnionStationHooksRails::ExceptionLogger)
57
+ end
@@ -0,0 +1,30 @@
1
+ # Union Station - https://www.unionstationapp.com/
2
+ # Copyright (c) 2010-2015 Phusion Holding B.V.
3
+ #
4
+ # "Union Station" and "Passenger" are trademarks of Phusion Holding B.V.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+
24
+ # Initialize garbage collector statistics
25
+ if GC.respond_to?(:enable_stats)
26
+ GC.enable_stats
27
+ end
28
+ if defined?(GC::Profiler) && GC::Profiler.respond_to?(:enable)
29
+ GC::Profiler.enable
30
+ end
@@ -0,0 +1,32 @@
1
+ # Union Station - https://www.unionstationapp.com/
2
+ # Copyright (c) 2010-2015 Phusion Holding B.V.
3
+ #
4
+ # "Union Station" and "Passenger" are trademarks of Phusion Holding B.V.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+
24
+
25
+ module UnionStationHooksRails
26
+ version_file = File.expand_path('version_data.rb', File.dirname(__FILE__))
27
+ version_data = eval(File.read(version_file))
28
+ MAJOR_VERSION = version_data[:major]
29
+ MINOR_VERSION = version_data[:minor]
30
+ TINY_VERSION = version_data[:tiny]
31
+ VERSION_STRING = version_data[:string]
32
+ end
@@ -0,0 +1,44 @@
1
+ # Union Station - https://www.unionstationapp.com/
2
+ # Copyright (c) 2010-2015 Phusion Holding B.V.
3
+ #
4
+ # "Union Station" and "Passenger" are trademarks of Phusion Holding B.V.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+
24
+ # This file contains union_station_hook_rails's version number. It is meant
25
+ # to be read and evaluated by the gemspec. We do not define any functions or
26
+ # modules here because we need to support the following situation:
27
+ #
28
+ # 1. Passenger loads its vendored union_station_hooks_* gems. This defines
29
+ # various modules.
30
+ # 2. The app specified union_station_hooks_* gems in its Gemfile, which
31
+ # indicates that it wants to override Passenger's vendored
32
+ # union_station_hooks_* gems with its own versions. This will cause Bundler
33
+ # to load union_station_hooks_*.gemspec.
34
+ #
35
+ # To make the gemspecs load properly and without affecting the already-loaded
36
+ # union_station_hooks_* gems code, we must not define any functions or modules
37
+ # here.
38
+
39
+ {
40
+ :major => 1,
41
+ :minor => 0,
42
+ :tiny => 0,
43
+ :string => '1.0.0'
44
+ }
@@ -0,0 +1,170 @@
1
+ # Union Station - https://www.unionstationapp.com/
2
+ # Copyright (c) 2010-2015 Phusion Holding B.V.
3
+ #
4
+ # "Union Station" and "Passenger" are trademarks of Phusion Holding B.V.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+
24
+ # Important notes:
25
+ #
26
+ # - We can't define a Railtie in this gem because union_station_hooks_rails
27
+ # may be loaded from Passenger, before Rails is loaded.
28
+ # - Make sure that you do not install any actual hooks until `initialize!`
29
+ # is called. Otherwise, union_station_hooks_core won't be able to properly
30
+ # upgrade the Union Station hook code vendored in Passenger.
31
+ # See https://github.com/phusion/union_station_hooks/hacking/Vendoring.md
32
+ # for more information.
33
+
34
+ if defined?(UnionStationHooksRails::VERSION_STRING)
35
+ if UnionStationHooksRails.initialized?
36
+ raise 'Attempted to load union_station_hooks_core even though an ' \
37
+ 'alternative version was already loaded and initialized'
38
+ end
39
+ if UnionStationHooksRails.vendored?
40
+ # Passenger loaded its vendored Union Station hooks code, but the
41
+ # application has also included 'union_station_hooks_*' in its Gemfile. We
42
+ # want the version in the Gemfile to take precedence, so we unload the old
43
+ # version. At this point, the Union Station hooks aren't installed yet, so
44
+ # removing the module is enough to unload the old version.
45
+ #
46
+ # See also:
47
+ # https://github.com/phusion/union_station_hooks/blob/master/hacking/Vendoring.md
48
+ if defined?(UnionStationHooks)
49
+ UnionStationHooks.initializers.delete(UnionStationHooksRails)
50
+ end
51
+ Object.send(:remove_const, :UnionStationHooksRails)
52
+ end
53
+ end
54
+
55
+ module UnionStationHooksRails
56
+ # The path to the `union_station_hooks_rails` Ruby library directory.
57
+ #
58
+ # @private
59
+ LIBROOT = File.expand_path(File.dirname(__FILE__))
60
+
61
+ # The path to the `union_station_hooks_rails` gem root directory.
62
+ #
63
+ # @private
64
+ ROOT = File.dirname(LIBROOT)
65
+
66
+ class << self
67
+ # @private
68
+ @@initialized = false
69
+ # @private
70
+ @@vendored = false
71
+
72
+ # Initializes `union_station_hooks_rails`. This method is automatically
73
+ # called by `UnionStationHooks.initialized!` because we registered
74
+ # ourselves in `UnionStationHooks.initializers`. The application does
75
+ # not need to call this.
76
+ #
77
+ # If this method successfully initializes, then it returns true.
78
+ #
79
+ # Calling this method may or may not actually initialize
80
+ # `union_station_hooks_rails`. If this gem determines that initialization
81
+ # is not desired, then this method won't do anything and will return
82
+ # `false`. See {UnionStationHooksRails#should_initialize?}.
83
+ #
84
+ # Initializing twice is a no-op. It only causes this method to return true.
85
+ #
86
+ # @private
87
+ # @return [Boolean] Whether initialization was successful.
88
+ def initialize!
89
+ return false if !should_initialize?
90
+ return true if initialized?
91
+
92
+ require_lib('initialize')
93
+ require_lib('active_record_subscriber')
94
+ require_lib('exception_logger')
95
+ if defined?(ActiveSupport::Cache::Store)
96
+ require_lib('active_support_cache_subscriber')
97
+ end
98
+ if defined?(ActionController::Base)
99
+ require_lib('action_controller_extension')
100
+ end
101
+ if defined?(ActiveSupport::Benchmarkable)
102
+ require_lib('active_support_benchmarkable_extension')
103
+ end
104
+
105
+ @@initialized = true
106
+
107
+ true
108
+ end
109
+
110
+ # Returns whether the Union Station hooks are initialized.
111
+ def initialized?
112
+ @@initialized
113
+ end
114
+
115
+ # Returns whether the Union Station hooks should be initialized. If this
116
+ # method returns false, then {UnionStationHooksRails.initialize!} doesn't
117
+ # do anything.
118
+ #
119
+ # This method only returns true if ActiveSupport >= 3 is currently loaded.
120
+ def should_initialize?
121
+ if defined?(::ActiveSupport) && !defined?(::ActiveSupport::VERSION)
122
+ require 'active_support/version'
123
+ end
124
+ defined?(::ActiveSupport) && ::ActiveSupport::VERSION::MAJOR >= 3
125
+ end
126
+
127
+ # Returns whether this `union_station_hooks_rails` gem is bundled with
128
+ # Passenger (as opposed to a standalone gem added to the Gemfile).
129
+ # See the README and the file `hacking/Vendoring.md` in the
130
+ # `union_station_hooks_core` gem for information about how Passenger
131
+ # bundles `union_station_hooks_*` gems.
132
+ #
133
+ # @private
134
+ def vendored?
135
+ @@vendored
136
+ end
137
+
138
+ # @private
139
+ def vendored=(val)
140
+ @@vendored = val
141
+ end
142
+
143
+ # @private
144
+ def require_lib(name)
145
+ require("#{LIBROOT}/union_station_hooks_rails/#{name}")
146
+ end
147
+
148
+ # @private
149
+ def require_and_check_union_station_hooks_core
150
+ if !defined?(UnionStationHooks::VERSION_STRING)
151
+ require 'union_station_hooks_core'
152
+ end
153
+
154
+ # If you update the dependency version here, also update
155
+ # the version in the gemspec and in the Gemfile.
156
+ compatible = UnionStationHooks::MAJOR_VERSION == 1 &&
157
+ UnionStationHooks::MINOR_VERSION >= 0
158
+ if !compatible
159
+ raise "This version of the union_station_hooks_rails gem " \
160
+ "(#{VERSION_STRING}) is only compatible with the " \
161
+ "union_station_hooks_core gem 1.x.x. However, you have loaded " \
162
+ "union_station_hooks_core #{UnionStationHooks::VERSION_STRING}"
163
+ end
164
+ end
165
+ end
166
+ end
167
+
168
+ UnionStationHooksRails.require_lib('version')
169
+ UnionStationHooksRails.require_and_check_union_station_hooks_core
170
+ UnionStationHooks.initializers << UnionStationHooksRails
@@ -0,0 +1,34 @@
1
+ version_file = File.expand_path('lib/union_station_hooks_rails/version_data.rb', File.dirname(__FILE__))
2
+ version_data = eval(File.read(version_file))
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "union_station_hooks_rails"
6
+ s.version = version_data[:string]
7
+ s.authors = ["Hongli Lai"]
8
+ s.description = "Union Station Rails hooks."
9
+ s.summary = "Union Station Rails hooks"
10
+ s.email = "info@phusion.nl"
11
+ s.license = "MIT"
12
+ s.files = Dir[
13
+ "README.md",
14
+ "LICENSE.md",
15
+ "*.gemspec",
16
+ "lib/**/*"
17
+ ]
18
+ s.homepage = "https://github.com/phusion/union_station_hooks_rails"
19
+ s.require_paths = ["lib"]
20
+
21
+ # If you update the dependency version here, also update
22
+ # the version in Gemfile and union_station_hooks_rails.rb method
23
+ # `require_and_check_union_station_hooks_core`
24
+ s.add_dependency("union_station_hooks_core", "~> 1.0")
25
+
26
+ s.add_dependency("activesupport", ">= 3.0")
27
+ s.add_dependency("activemodel", ">= 3.0")
28
+ s.add_dependency("actionpack", ">= 3.0")
29
+ s.add_dependency("railties", ">= 3.0")
30
+
31
+ # DO NOT ADD ANY FURTHER DEPENDENCIES! See
32
+ # https://github.com/phusion/union_station_hooks_core/blob/master/hacking/Vendoring.md,
33
+ # section "No dependencies", for more information.
34
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: union_station_hooks_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Hongli Lai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: union_station_hooks_core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activemodel
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: actionpack
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: railties
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Union Station Rails hooks.
84
+ email: info@phusion.nl
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - LICENSE.md
90
+ - README.md
91
+ - lib/union_station_hooks_rails.rb
92
+ - lib/union_station_hooks_rails/action_controller_extension.rb
93
+ - lib/union_station_hooks_rails/active_record_subscriber.rb
94
+ - lib/union_station_hooks_rails/active_support_benchmarkable_extension.rb
95
+ - lib/union_station_hooks_rails/active_support_cache_subscriber.rb
96
+ - lib/union_station_hooks_rails/exception_logger.rb
97
+ - lib/union_station_hooks_rails/initialize.rb
98
+ - lib/union_station_hooks_rails/version.rb
99
+ - lib/union_station_hooks_rails/version_data.rb
100
+ - union_station_hooks_rails.gemspec
101
+ homepage: https://github.com/phusion/union_station_hooks_rails
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.2.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Union Station Rails hooks
125
+ test_files: []
126
+ has_rdoc: