rails-etcs 0.1.0.beta2 → 0.1.0.beta3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a32d6b5756f24bd469be9368fe4d3f616fad340da550d28e0b7be27815538e7b
4
- data.tar.gz: 07b1f9ee4c086c04a2b06ecdcd6e12cef94416881cba1a6cb0702f8c85b70936
3
+ metadata.gz: e2b1136012e22d9ec9e8be3561c1fd2e6596df1c4a5db2189cf567fb420440fc
4
+ data.tar.gz: b82da6f787f7c42f9f374fcee9ff45651884dc7d96e8a6817a277bda59433622
5
5
  SHA512:
6
- metadata.gz: f3f5fc7f5e9e761618b316adaa6a3bdeac33213880d2e12f7a80b3d4cf293bf77e4340c03924f7a00ef5573d8e64070aac22e669d54b5f49ceaf6a590e51d444
7
- data.tar.gz: 5a4a54e5430cb7a0ce50b05ae942e6dbab8918a25686aee2aad6e38548312e11be6fb5d29a8050c0c19c45f33ef8677206d6cf9a82a7d15f06883a38ec67ac2d
6
+ metadata.gz: aedbf7efe88f3314d7d12721b451ebe4df6affbe000e425a88924d1b1f806b6a7c553dd8ba5e1fb0bbe0691de45dea48a1781b58a1b9d6e86487e264de196584
7
+ data.tar.gz: 524a96fd53f1f7269881313bd4ab4a0bb135b256bf3d63d86bace93035c4cc4373a90622428aef25ce1282dbff2fa43a22732e9490021a579d0605ab09cffb05
data/Appraisals CHANGED
@@ -13,7 +13,7 @@ appraise 'rails-5.1' do
13
13
  end
14
14
 
15
15
  appraise 'rails-5.2' do
16
- gem 'rails', '~> 5.2.0.rc'
16
+ gem 'rails', '~> 5.2.0'
17
17
  end
18
18
 
19
19
  appraise 'rails-head' do
data/Gemfile CHANGED
@@ -11,3 +11,6 @@ gem 'appraisal'
11
11
  gem 'rake'
12
12
  gem 'rake-release'
13
13
  gem 'rspec', '~> 3.0'
14
+
15
+ gem 'pry'
16
+ gem 'pry-byebug'
data/README.md CHANGED
@@ -2,21 +2,18 @@
2
2
 
3
3
  A collection of patches and alternatives for Rails core classes.
4
4
 
5
- ## Installation
6
-
7
- If you cannot install the gem alone you should better not use it.
8
-
9
5
  ## Usage
10
6
 
11
7
  ### Rails::Etcs::Application
12
8
 
13
- `Rails::Etcs::Application` can be used instead of `Rails::Application` when creating your own applications:
9
+ `Rails::Etcs::Application` can be included when creating your application:
14
10
 
15
11
  ```ruby
16
12
  # my-app/config/application.rb
17
13
 
18
14
  module MyApp
19
- class Application < ::Rails::Etcs::Application
15
+ class Application < ::Rails::Application
16
+ include ::Rails::Etcs::Application
20
17
  self.ident = 'my-app'
21
18
  end
22
19
  end
@@ -46,6 +43,24 @@ You can customize the application name via `self.ident = 'my-app'`. Configuratio
46
43
  The same lookup is applied for `database.yml`, `secrets.yml`, and additional
47
44
  initializers and environments files.
48
45
 
46
+ #### `#config_for`
47
+
48
+ `#config_for` has been patched with additional functionality.
49
+
50
+ It returns the full parsed config instead of the environment key when `env: false` is passed:
51
+
52
+ ```ruby
53
+ config_for('database', env: false) # => {'development' => ..., 'test' => ..., ...}
54
+ ```
55
+
56
+ The additional `quiet` keyword argument can be used to suppress a file not found exception. Together with the new `yield` support you can easily handle optional configuration:
57
+
58
+ ```ruby
59
+ config_for('may-exist-or-not', quiet: true) do |conf|
60
+ # ...
61
+ end
62
+ ```
63
+
49
64
  ## License
50
65
 
51
66
  Rails::Etcs (c) 2018 Jan Graichen
@@ -4,7 +4,10 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
6
  gem "rake"
7
+ gem "rake-release"
7
8
  gem "rspec", "~> 3.0"
9
+ gem "pry"
10
+ gem "pry-byebug"
8
11
  gem "rails", "~> 4.2.0"
9
12
 
10
13
  gemspec path: "../"
@@ -4,7 +4,10 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
6
  gem "rake"
7
+ gem "rake-release"
7
8
  gem "rspec", "~> 3.0"
9
+ gem "pry"
10
+ gem "pry-byebug"
8
11
  gem "rails", "~> 5.0.0"
9
12
 
10
13
  gemspec path: "../"
@@ -4,7 +4,10 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
6
  gem "rake"
7
+ gem "rake-release"
7
8
  gem "rspec", "~> 3.0"
9
+ gem "pry"
10
+ gem "pry-byebug"
8
11
  gem "rails", "~> 5.1.0"
9
12
 
10
13
  gemspec path: "../"
@@ -4,7 +4,10 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
6
  gem "rake"
7
+ gem "rake-release"
7
8
  gem "rspec", "~> 3.0"
8
- gem "rails", "~> 5.2.0.rc"
9
+ gem "pry"
10
+ gem "pry-byebug"
11
+ gem "rails", "~> 5.2.0"
9
12
 
10
13
  gemspec path: "../"
@@ -4,7 +4,10 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
6
  gem "rake"
7
+ gem "rake-release"
7
8
  gem "rspec", "~> 3.0"
9
+ gem "pry"
10
+ gem "pry-byebug"
8
11
  gem "rails", git: "https://github.com/rails/rails"
9
12
 
10
13
  gemspec path: "../"
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'xdg'
4
4
 
5
- class Rails::Etcs::Application
5
+ module Rails::Etcs::Application
6
6
  class Configuration < ::Rails::Application::Configuration
7
7
  attr_reader :ident
8
8
 
@@ -47,6 +47,15 @@ class Rails::Etcs::Application
47
47
  with: paths['config'],
48
48
  glob: 'secrets.yml{,.enc}'
49
49
 
50
+ if Gem::Requirement.new('< 5.1') =~ Gem::Version.new(Rails.version)
51
+ # Rails < 5.1 does not check for existing secrets file but just
52
+ # uses the first path even if it does not exist.
53
+ #
54
+ # This workaround fixes that by pre-expanding the path with only
55
+ # existing files.
56
+ paths.add 'config/secrets', with: paths['config/secrets'].existent
57
+ end
58
+
50
59
  paths['config'].to_ary.reverse.each do |dir|
51
60
  paths['config/initializers'] << File.join(dir, 'initializers')
52
61
  paths['config/environments'] << File.join(dir, 'environments')
@@ -1,9 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rails::Etcs
4
- class Application < ::Rails::Application
4
+ module Application
5
+ extend ActiveSupport::Concern
6
+
5
7
  require 'rails/etcs/application/configuration'
6
8
 
9
+ included do
10
+ attr_writer :ident
11
+
12
+ def ident
13
+ @ident ||= begin
14
+ self.class.name.underscore
15
+ .gsub(/[^A-z]+/, '-')
16
+ .gsub(/-application$/, '')
17
+ end
18
+ end
19
+ end
20
+
7
21
  def config
8
22
  @config ||= begin
9
23
  root = self.class.find_root self.class.called_from
@@ -14,7 +28,8 @@ module Rails::Etcs
14
28
 
15
29
  # rubocop:disable AbcSize
16
30
  # rubocop:disable MethodLength
17
- def config_for(name, env: Rails.env)
31
+ # rubocop:disable CyclomaticComplexity
32
+ def config_for(name, env: Rails.env, quiet: false)
18
33
  files = paths['config']
19
34
  .expanded
20
35
  .map {|d| Pathname.new(d).join("#{name}.yml") }
@@ -22,13 +37,18 @@ module Rails::Etcs
22
37
  yaml = files.find(&:exist?)
23
38
 
24
39
  unless yaml
40
+ return if quiet
25
41
  raise "Could not load configuration. No such file - #{files.join(', ')}"
26
42
  end
27
43
 
28
44
  require 'erb'
29
45
 
30
46
  data = YAML.safe_load(ERB.new(yaml.read).result, [], [], true) || {}
31
- data.fetch(env, {})
47
+ data = env ? data.fetch(env, {}) : data
48
+
49
+ yield data if block_given?
50
+
51
+ data
32
52
  rescue Psych::SyntaxError => e
33
53
  raise <<~ERR
34
54
  YAML syntax error occurred while parsing #{yaml}.
@@ -38,15 +58,5 @@ module Rails::Etcs
38
58
  ERR
39
59
  end
40
60
  # rubocop:enable all
41
-
42
- class << self
43
- attr_writer :ident
44
-
45
- def ident
46
- @ident ||= begin
47
- name.underscore.gsub(/[^A-z]+/, '-').gsub(/-application$/, '')
48
- end
49
- end
50
- end
51
61
  end
52
62
  end
@@ -6,7 +6,7 @@ module Rails
6
6
  MAJOR = 0
7
7
  MINOR = 1
8
8
  PATCH = 0
9
- STAGE = :beta2
9
+ STAGE = :beta3
10
10
 
11
11
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.').freeze
12
12
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-etcs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta2
4
+ version: 0.1.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-20 00:00:00.000000000 Z
11
+ date: 2018-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xdg
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  version: 1.3.1
108
108
  requirements: []
109
109
  rubyforge_project:
110
- rubygems_version: 2.7.3
110
+ rubygems_version: 2.7.7
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: Collection of patches and alternatives for Rails core classes