a9n 0.9.1 → 0.10.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
  SHA256:
3
- metadata.gz: d25e665f63827ffa8e6e813bec78b80736dbc6e321659465b7758c70eb7a93d5
4
- data.tar.gz: '0587ac992772835f359d251375a8565606c812f63796a87b91c978b4bfc7b99f'
3
+ metadata.gz: 4ee6b81b16b79243d8124f9cc0565dfb4e2da7814c49a1b0fdf564e1db54ba1d
4
+ data.tar.gz: 0f09a8578098ca8d894b5dc5fa51030e009dbe175b0ac1d42e1b43d078bb4e0f
5
5
  SHA512:
6
- metadata.gz: cd9dd712d5e296798537ee5ded3647a11907645da77b0495154e3ff194af381ad45961d3d1c3b269987f78650c3dc1ee8ac24f35f5ad99742801580f528a4d6b
7
- data.tar.gz: 65f3792eaadc7d9d4cd846992b5669dcedb8924cf6eb7e84c8889ce1925392a621e40974407044385c12afb3a754f1bb61c765b4acf9eea3c14c13350508c354
6
+ metadata.gz: 324a28691a19dfd3455c55525221c17629e88036adbfad6f819f165e336647d4022c4cf6a1db71546595519447fbab3a94fd343d6faf1911bd710df57f206f45
7
+ data.tar.gz: 27ae7fc1b29f3714049a37ee55173dd658cb553435c70cdc12de7e118d6b1e9485e74766a4dacf7f63307d7df1a5cf6765f487bcc884918cd83fcb881ad5792e
data/Rakefile CHANGED
@@ -1,10 +1,13 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
3
 
4
+ require 'rubocop/rake_task'
5
+ RuboCop::RakeTask.new
6
+
4
7
  desc 'Run all specs'
5
8
  RSpec::Core::RakeTask.new(:spec) do |t|
6
9
  t.pattern = './spec/**/*_spec.rb'
7
10
  t.rspec_opts = ['--profile', '--color']
8
11
  end
9
12
 
10
- task default: :spec
13
+ task default: [:spec, :rubocop]
data/lib/a9n.rb CHANGED
@@ -45,7 +45,7 @@ module A9n
45
45
  end
46
46
 
47
47
  def root
48
- @root ||= app_root || root_from_bundle_env || fail(RootNotSetError)
48
+ @root ||= app_root || root_from_bundle_env || raise(RootNotSetError)
49
49
  end
50
50
 
51
51
  def app_root
@@ -54,8 +54,11 @@ module A9n
54
54
 
55
55
  def root_from_bundle_env
56
56
  return nil unless ENV['BUNDLE_GEMFILE']
57
+
57
58
  dir = File.dirname(ENV['BUNDLE_GEMFILE'])
59
+
58
60
  return nil unless File.directory?(dir)
61
+
59
62
  Pathname.new(dir)
60
63
  end
61
64
 
@@ -84,7 +87,7 @@ module A9n
84
87
  def default_files
85
88
  files = Dir[root.join("config/{#{A9n::Scope::ROOT_NAMES.join(',')}}.#{EXTENSION_LIST}").to_s]
86
89
  files += Dir[root.join("config/a9n/*.#{EXTENSION_LIST}")]
87
- files.map { |f| f.sub(/.example$/, '') }.uniq
90
+ files.map { |f| f.sub(/.example$/, '') }.uniq.sort
88
91
  end
89
92
 
90
93
  def load(*files)
@@ -1,4 +1,4 @@
1
- # https://github.com/rails/rails/edit/master/activesupport/lib/active_support/string_inquirer.rb
1
+ # Based on https://github.com/rails/rails/blob/master/activesupport/lib/active_support/string_inquirer.rb
2
2
  module A9n
3
3
  class StringInquirer < String
4
4
  private
@@ -2,7 +2,8 @@ module A9n
2
2
  class Loader
3
3
  attr_reader :scope, :env, :local_file, :example_file, :struct
4
4
 
5
- COMMON_SCOPE = 'defaults'.freeze
5
+ COMMON_NAMESPACE = 'defaults'.freeze
6
+ KNOWN_NAMESPACES = [COMMON_NAMESPACE, 'development', 'test', 'staging', 'production'].freeze
6
7
 
7
8
  def initialize(file_path, scope, env)
8
9
  @scope = scope
@@ -31,16 +32,24 @@ module A9n
31
32
 
32
33
  yml = YAML.load(ERB.new(File.read(file_path)).result)
33
34
 
34
- common_scope = prepare_yml_scope(yml, scope, COMMON_SCOPE)
35
- env_scope = prepare_yml_scope(yml, scope, env)
35
+ if no_known_namespaces?(yml)
36
+ prepare_hash(yml, scope).freeze
37
+ else
38
+ common_namespace = prepare_hash(yml[COMMON_NAMESPACE], scope)
39
+ env_namespace = prepare_hash(yml[env], scope)
36
40
 
37
- A9n::Hash.merge(common_scope, env_scope).freeze
41
+ A9n::Hash.merge(common_namespace, env_namespace).freeze
42
+ end
38
43
  end
39
44
 
40
- def prepare_yml_scope(yml, scope, env)
41
- return nil unless yml[env].is_a?(::Hash)
45
+ def prepare_hash(data, scope)
46
+ return nil unless data.is_a?(::Hash)
42
47
 
43
- A9n::Hash.deep_prepare(yml[env], scope).freeze
48
+ A9n::Hash.deep_prepare(data, scope).freeze
49
+ end
50
+
51
+ def no_known_namespaces?(yml)
52
+ (yml.keys & KNOWN_NAMESPACES).empty?
44
53
  end
45
54
  end
46
55
 
@@ -1,3 +1,3 @@
1
1
  module A9n
2
- VERSION = '0.9.1'.freeze
2
+ VERSION = '0.10.0'.freeze
3
3
  end
@@ -130,4 +130,21 @@ RSpec.describe A9n do
130
130
  expect(subject.fetch(:mailer)).to eq(subject.mailer)
131
131
  end
132
132
  end
133
+
134
+ context 'extra config file without known namspaces' do
135
+ before do
136
+ expect(subject.emails).to be_kind_of(A9n::Struct)
137
+ end
138
+
139
+ it do
140
+ expect(subject.emails.knapo).to eq('knapo@a9n.local')
141
+ expect(subject.emails.admin).to eq('admin@a9n.local')
142
+ expect { subject.emails.foo }.to raise_error(A9n::NoSuchConfigurationVariableError)
143
+ end
144
+
145
+ it do
146
+ expect(subject.emails.fetch(:knapo)).to eq('knapo@a9n.local')
147
+ expect(subject.emails.fetch(:admin)).to eq('admin@a9n.local')
148
+ end
149
+ end
133
150
  end
@@ -127,17 +127,7 @@ RSpec.describe A9n do
127
127
 
128
128
  context 'when app is not set' do
129
129
  it do
130
- expect(subject.root).to eq(nil)
131
- end
132
-
133
- context 'when setting a custom path when is falsy' do
134
- before do
135
- subject.root ||= '/home/knapo/workspace/a9n'
136
- end
137
-
138
- it do
139
- expect(subject.root).to eq(Pathname.new('/home/knapo/workspace/a9n'))
140
- end
130
+ expect(subject.root).to eq(A9n.root_from_bundle_env)
141
131
  end
142
132
 
143
133
  context 'when setting a custom path' do
@@ -0,0 +1,2 @@
1
+ knapo: "knapo@a9n.local"
2
+ admin: "admin@a9n.local"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: a9n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krzysztof Knapik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-28 00:00:00.000000000 Z
11
+ date: 2019-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codeclimate-test-reporter
@@ -136,6 +136,7 @@ files:
136
136
  - test_app/config/a9n.yml.example
137
137
  - test_app/config/a9n/aws.yml
138
138
  - test_app/config/a9n/cloud.yml.erb
139
+ - test_app/config/a9n/emails.yml
139
140
  - test_app/config/a9n/mailer.yml.example
140
141
  - test_app/config/no_defaults.yml
141
142
  homepage: https://github.com/knapo/a9n