initialize 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6712de1db3bb91c900565cde1abb7526d07592b5
4
- data.tar.gz: f389a3c4d4d84405de180fd29ec5e4a537965f7e
3
+ metadata.gz: 76d6a733de9590fbac166f9075124a940d360a3b
4
+ data.tar.gz: 56f1dac5bf848004a360a77397d32a439419dc0e
5
5
  SHA512:
6
- metadata.gz: 7bafee335baec4d480e04a3d670c978149145df5cc5575c19fbe96229f1cede0d295f5f752f15d4b6f9617dcc71e4ab0520ee4c88a9d50b044663792a5ebfaaa
7
- data.tar.gz: b342b6c542f1d56c858f6953f5936efddd435da727f0c8e13fae86639275cc1f9496f0f15d853ec8a357f537b41bd74380520d1150de071e570fdbd513bb3a41
6
+ metadata.gz: 10bb0fefc26a6f733dca5f0a4c6e56d074c36d0599539ed0ac416c62f48c456909e8ee7f4917f34358b972ff5d120bf11c5ca263cc12bd5194f4bf6864732a1b
7
+ data.tar.gz: 5b38cda7cd43d0e347b1a0bd9f89137e09840104eaeb0b81d8d81612ae01079ad0ca25b8ed2ef1840846a7c05ee60e9686bf2456c0046a6a416e32cfb5c863aa
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # initialize [![Gem version](http://img.shields.io/gem/v/initialize.svg?style=flat-square)](http://rubygems.org/gems/initialize)
2
2
 
3
- Ruby gem.
3
+ Ruby gem to completely customize the execution order of Rails config initializers.
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Add this line to your application's `Gemfile`:
8
8
 
9
9
  ```ruby
10
10
  gem 'initialize'
@@ -15,3 +15,73 @@ And then execute:
15
15
  ```bash
16
16
  $ bundle install
17
17
  ```
18
+
19
+ ## Usage
20
+
21
+ For example, say you have the following Ruby on Rails application:
22
+
23
+ ```
24
+ ├── app
25
+ ├── bin
26
+ ├── config
27
+ │   ├── environments
28
+ │   ├── initializers
29
+ │   │   ├── assets.rb
30
+ │   │   ├── backtrace_silencers.rb
31
+ │   │   ├── configure_rollbar.rb
32
+ │   │   ├── filter_parameter_logging.rb
33
+ │   │   ├── inflections.rb
34
+ │   │   ├── init_hub_settings.rb
35
+ │   │   ├── load_extensions.rb
36
+ │   │   ├── mime_types.rb
37
+ │   │   ├── schedule_app_launches.rb
38
+ │   │   ├── schedule_app_upgrades.rb
39
+ │   │   ├── schedule_hub_upgrades.rb
40
+ │   │   ├── schedule_ngrok.rb
41
+ │   │   ├── schedule_task_executions.rb
42
+ │   │   ├── session_store.rb
43
+ │   │   └── wrap_parameters.rb
44
+ │   ├── application.rb
45
+ │   ├── boot.rb
46
+ │   ├── database.yml
47
+ │   ├── environment.rb
48
+ │   ├── routes.rb
49
+ │   └── secrets.yml
50
+ ├── db
51
+ ├── lib
52
+ ├── public
53
+ ├── Gemfile
54
+ ├── Gemfile.lock
55
+ ├── Rakefile
56
+ └── README.md
57
+ ```
58
+
59
+ By default, Rails will run the files in `config/initializers` in alphabetical (filename) order, which isn't always what you want. To get around this, [the Rails team suggests prefixing initializer filenames with a numeric value](http://guides.rubyonrails.org/configuring.html#using-initializer-files), but such a solution is not the most elegant in my opinion.
60
+
61
+ With this gem, elegant control is back in your hands; you can define an `initializers` array in `config/application.rb` like so:
62
+
63
+ ```ruby
64
+ class Application < Rails::Application
65
+ config.initializers = [
66
+ "assets",
67
+ "backtrace_silencers",
68
+ "filter_parameter_logging",
69
+ "inflections",
70
+ "mime_types",
71
+ "session_store",
72
+ "wrap_parameters",
73
+ "load_extensions",
74
+ "init_hub_settings",
75
+ "configure_rollbar",
76
+ "schedule_ngrok",
77
+ "schedule_hub_upgrades",
78
+ "schedule_app_upgrades",
79
+ "schedule_app_launches",
80
+ "schedule_task_executions"
81
+ ]
82
+ end
83
+ ```
84
+
85
+ Notice how the ordering of initializers is not alphabetical? When the application starts, initializers will run in the order that they appear in the array!
86
+
87
+ Additionally, this opens up interesting possibilities for your Rails application, like (for example) enabling/disabling specific initializers based on some condition determined at runtime.
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Initialize::VERSION
9
9
  spec.authors = ["Luke Horvat"]
10
10
  spec.email = ["lukehorvat@gmail.com"]
11
- spec.summary = %q{Ruby gem.}
12
- spec.description = %q{Ruby gem.}
11
+ spec.summary = %q{Ruby gem to customize the run order of Rails initializers.}
12
+ spec.description = %q{Ruby gem to completely customize the execution order of Rails config initializers.}
13
13
  spec.homepage = "https://github.com/lukehorvat/initialize"
14
14
  spec.license = "MIT"
15
15
  spec.files = `git ls-files -z`.split("\x0")
@@ -1,3 +1,13 @@
1
+ =begin
2
+ Monkey-patch the "run" method of Rails::Initializable::Initializer so that it executes
3
+ initializers in a custom order defined by the user, not alphabetical order.
4
+
5
+ Relevant reference files from Rails core:
6
+ - https://github.com/rails/rails/blob/v4.2.5.2/railties/lib/rails/initializable.rb
7
+ - https://github.com/rails/rails/blob/v4.2.5.2/railties/lib/rails/engine.rb
8
+ - https://github.com/rails/rails/blob/v4.2.5.2/railties/lib/rails/application.rb
9
+ =end
10
+
1
11
  module Initialize
2
12
  module Patch
3
13
  def run(*args)
@@ -1,3 +1,3 @@
1
1
  module Initialize
2
- VERSION = "0.0.2"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: initialize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Horvat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-04 00:00:00.000000000 Z
11
+ date: 2016-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,7 +38,8 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
- description: Ruby gem.
41
+ description: Ruby gem to completely customize the execution order of Rails config
42
+ initializers.
42
43
  email:
43
44
  - lukehorvat@gmail.com
44
45
  executables: []
@@ -74,8 +75,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
75
  version: '0'
75
76
  requirements: []
76
77
  rubyforge_project:
77
- rubygems_version: 2.2.2
78
+ rubygems_version: 2.4.5.1
78
79
  signing_key:
79
80
  specification_version: 4
80
- summary: Ruby gem.
81
+ summary: Ruby gem to customize the run order of Rails initializers.
81
82
  test_files: []