a9n 0.7.0 → 0.8.0

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: 2d6b3183902e220ce9b3159af50976f1a13ad2e7eecd37b8ddc63cc461b2cbd3
4
- data.tar.gz: cae9ed3830fe21623e856349703378526b38f653bcd9ca9393d102050ae5b798
3
+ metadata.gz: 6c01e44cda9bcf5236abb9f3e48b210770559debc113dd329eb9be58be5e6ffb
4
+ data.tar.gz: 19cc16d440842053dd4deaf3534fa4367d4be03d72f672249d42bfd133e24fd5
5
5
  SHA512:
6
- metadata.gz: a436c129417fefef0e2fbdb728b83b18cf9e1ee9192303737fa9d00bde7bc2189f98228a58a0db44e6b6a233524d7e8a94d418de37f83c68c28634a4e459cbb8
7
- data.tar.gz: af4055cef9c76f29d9146ed4c3471b6885491d5c193c641a24bc432ed69bf7578dda31b10a5fbb69ed75a9924a33d0d02cfe2365245f844bf5d64033e9b80261
6
+ metadata.gz: a5258bfce395c5b2af491824036833601979f1f0b7fbb7bd22d999549698e0240de74911c92bf83acc7e5db61a1ad34015799783ae1dffc4877b03d02ce0bf09
7
+ data.tar.gz: 185d114b3f8db2aefefe5e4a8a4b434b19be429d6c28b1d840c45e7d91e1537fb47c11410097192ac3d6c8141ea73a2afeda083c6985c96051ca3e47837d8d52
data/README.md CHANGED
@@ -75,6 +75,17 @@ You can access it by:
75
75
  A9n.mail.email_from # => `knapo@knapo.net`
76
76
  A9n.mail.delivery_method # => `smtp`
77
77
 
78
+ ## Setting variables manually
79
+
80
+ You can set variables manually using `A9n.set` method
81
+
82
+ A9n.set(:app_host, "localhost:3000")
83
+ A9n.app_host # => `localhost:3000`
84
+
85
+ To reload/restore configuration:
86
+
87
+ A9n.load
88
+
78
89
  ## Mapping ENV variables
79
90
 
80
91
  Sometimes, you don't want to store a single secret value in the repo and you prefer having it in ENV variable. You can easily map it using `:env` symbol as a value:
@@ -2,17 +2,16 @@ module A9n
2
2
  class Struct
3
3
  extend Forwardable
4
4
 
5
+ attr_reader :data
6
+
5
7
  def_delegators :data, :empty?, :keys, :key?, :fetch, :[], :[]=
6
8
 
7
9
  def initialize(data = {})
8
10
  @data = data
9
11
  end
10
12
 
11
- def to_hash
12
- data
13
- end
14
-
15
- alias to_h to_hash
13
+ alias to_hash data
14
+ alias to_h data
16
15
 
17
16
  def merge(another_data)
18
17
  data.merge!(another_data)
@@ -26,8 +25,8 @@ module A9n
26
25
  end
27
26
  end
28
27
 
29
- private
30
-
31
- attr_reader :data
28
+ def set(key, value)
29
+ data[key.to_sym] = value
30
+ end
32
31
  end
33
32
  end
@@ -1,3 +1,3 @@
1
1
  module A9n
2
- VERSION = '0.7.0'.freeze
2
+ VERSION = '0.8.0'.freeze
3
3
  end
@@ -7,7 +7,7 @@ RSpec.describe A9n do
7
7
  clean_singleton(subject)
8
8
  ENV['ERB_DWARF'] = 'erbized dwarf'
9
9
  ENV['DWARF_PASSWORD'] = 'dwarf123'
10
- ENV['MANDRILL_API_KEY'] = 'ASDF1234'
10
+ ENV['AWS_API_KEY'] = 'ASDF1234'
11
11
  ENV['API_KEY'] = 'XYZ999'
12
12
  subject.app = double(env: env)
13
13
  subject.root = File.expand_path('../../test_app', __dir__)
@@ -16,7 +16,7 @@ RSpec.describe A9n do
16
16
 
17
17
  after do
18
18
  clean_singleton(subject)
19
- ENV.delete('MANDRILL_API_KEY')
19
+ ENV.delete('GOOGLE_API_KEY')
20
20
  ENV.delete('API_KEY')
21
21
  end
22
22
 
@@ -28,6 +28,13 @@ RSpec.describe A9n do
28
28
  it do
29
29
  expect(subject.default_dwarf).to eq('default dwarf')
30
30
  expect(subject.overriden_dwarf).to eq('already overriden dwarf')
31
+ subject.set(:default_dwarf, 'lazy dwarf')
32
+ subject.set(:overriden_dwarf, 'hard working dwarf')
33
+ expect(subject.default_dwarf).to eq('lazy dwarf')
34
+ expect(subject.overriden_dwarf).to eq('hard working dwarf')
35
+ subject.load
36
+ expect(subject.default_dwarf).to eq('default dwarf')
37
+ expect(subject.overriden_dwarf).to eq('already overriden dwarf')
31
38
  end
32
39
 
33
40
  it do
@@ -64,21 +71,21 @@ RSpec.describe A9n do
64
71
 
65
72
  context 'extra config file' do
66
73
  before do
67
- expect(subject.mandrill).to be_kind_of(A9n::Struct)
74
+ expect(subject.aws).to be_kind_of(A9n::Struct)
68
75
  end
69
76
 
70
77
  it do
71
- expect(subject.mandrill.username).to eq('joe')
72
- expect(subject.mandrill.api_key).to eq('ASDF1234')
78
+ expect(subject.aws.username).to eq('joe')
79
+ expect(subject.aws.api_key).to eq('ASDF1234')
73
80
  end
74
81
 
75
82
  it do
76
- expect(subject.mandrill.fetch(:username)).to eq('joe')
77
- expect(subject.mandrill.fetch(:api_key)).to eq('ASDF1234')
83
+ expect(subject.aws.fetch(:username)).to eq('joe')
84
+ expect(subject.aws.fetch(:api_key)).to eq('ASDF1234')
78
85
  end
79
86
 
80
87
  it do
81
- expect(subject.fetch(:mandrill)).to eq(subject.mandrill)
88
+ expect(subject.fetch(:aws)).to eq(subject.aws)
82
89
  end
83
90
  end
84
91
 
@@ -167,9 +167,9 @@ RSpec.describe A9n do
167
167
  end
168
168
 
169
169
  it do
170
- expect(subject.default_files[0]).to include('configuration.yml')
170
+ expect(subject.default_files[0]).to include('a9n.yml')
171
171
  expect(Pathname.new(subject.default_files[0])).to be_absolute
172
- expect(subject.default_files[1]).to include('a9n/mandrill.yml')
172
+ expect(subject.default_files[1]).to include('a9n/aws.yml')
173
173
  expect(Pathname.new(subject.default_files[1])).to be_absolute
174
174
  end
175
175
  end
@@ -1,8 +1,8 @@
1
1
  RSpec.describe A9n::Loader do
2
- let(:scope) { A9n::Scope.new('configuration') }
2
+ let(:scope) { A9n::Scope.new('a9n') }
3
3
  let(:env) { 'test' }
4
4
  let(:root) { File.expand_path('../../test_app', __dir__) }
5
- let(:file_path) { File.join(root, 'config/configuration.yml') }
5
+ let(:file_path) { File.join(root, 'config/a9n.yml') }
6
6
  subject { described_class.new(file_path, scope, env) }
7
7
 
8
8
  describe '#intialize' do
@@ -135,7 +135,7 @@ RSpec.describe A9n::Loader do
135
135
  end
136
136
 
137
137
  context 'having env and defaults data' do
138
- let(:file_path) { File.join(root, 'config/configuration.yml') }
138
+ let(:file_path) { File.join(root, 'config/a9n.yml') }
139
139
 
140
140
  it_behaves_like 'non-empty config file'
141
141
 
@@ -170,7 +170,7 @@ RSpec.describe A9n::Loader do
170
170
  end
171
171
 
172
172
  context 'having no env and only defaults data' do
173
- let(:file_path) { File.join(root, 'config/configuration.yml') }
173
+ let(:file_path) { File.join(root, 'config/a9n.yml') }
174
174
  let(:env) { 'production' }
175
175
 
176
176
  it_behaves_like 'non-empty config file'
@@ -13,15 +13,15 @@ RSpec.describe A9n::Scope do
13
13
  end
14
14
 
15
15
  context 'when name is other than configuration' do
16
- let(:name) { 'mandrill' }
16
+ let(:name) { 'google' }
17
17
  it { expect(subject).not_to be_root }
18
18
  end
19
19
  end
20
20
 
21
21
  describe '.form_file_path' do
22
- let(:path) { 'config/a9n/mandrill.yml.example' }
22
+ let(:path) { 'config/a9n/google.yml.example' }
23
23
  subject { described_class.form_file_path(path) }
24
24
 
25
- it { expect(subject.name).to eq(:mandrill) }
25
+ it { expect(subject.name).to eq(:google) }
26
26
  end
27
27
  end
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.7.0
4
+ version: 0.8.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-06-11 00:00:00.000000000 Z
11
+ date: 2019-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codeclimate-test-reporter
@@ -132,11 +132,11 @@ files:
132
132
  - spec/unit/scope_spec.rb
133
133
  - spec/unit/struct_spec.rb
134
134
  - test_app/benchmark.rb
135
+ - test_app/config/a9n.yml
136
+ - test_app/config/a9n.yml.example
137
+ - test_app/config/a9n/aws.yml
135
138
  - test_app/config/a9n/cloud.yml.erb
136
139
  - test_app/config/a9n/mailer.yml.example
137
- - test_app/config/a9n/mandrill.yml
138
- - test_app/config/configuration.yml
139
- - test_app/config/configuration.yml.example
140
140
  - test_app/config/no_defaults.yml
141
141
  homepage: https://github.com/knapo/a9n
142
142
  licenses: