a9n 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +9 -0
- data/Gemfile +1 -0
- data/README.md +5 -3
- data/Rakefile +10 -1
- data/lib/a9n.rb +13 -6
- data/lib/a9n/version.rb +1 -1
- data/spec/a9n_spec.rb +21 -6
- metadata +3 -2
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# A9n
|
2
2
|
|
3
|
-
|
3
|
+
[![Build status](https://secure.travis-ci.org/knapo/a9n.png)](https://travis-ci.org/knapo/a9n)
|
4
|
+
|
5
|
+
Simple tool for managing ruby/rails application configurations.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -12,9 +14,9 @@ And then execute:
|
|
12
14
|
|
13
15
|
$ bundle
|
14
16
|
|
15
|
-
|
17
|
+
In your `application.rb` load configuration with:
|
16
18
|
|
17
|
-
|
19
|
+
A9n.load
|
18
20
|
|
19
21
|
## Usage
|
20
22
|
|
data/Rakefile
CHANGED
@@ -1,2 +1,11 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
require
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
desc 'Run all specs'
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
7
|
+
t.pattern = './spec/**/*_spec.rb'
|
8
|
+
t.rspec_opts = ['--profile', '--color']
|
9
|
+
end
|
10
|
+
|
11
|
+
task :default => :spec
|
data/lib/a9n.rb
CHANGED
@@ -4,6 +4,7 @@ require 'a9n/store'
|
|
4
4
|
module A9n
|
5
5
|
class ConfigurationNotLoaded < StandardError; end
|
6
6
|
class MissingConfigurationFile < StandardError; end
|
7
|
+
class MissingConfigurationData < StandardError; end
|
7
8
|
class MissingConfigurationVariables < StandardError; end
|
8
9
|
class NoSuchConfigurationVariable < StandardError; end
|
9
10
|
|
@@ -12,19 +13,19 @@ module A9n
|
|
12
13
|
def cfg
|
13
14
|
@@configuration
|
14
15
|
rescue NameError
|
15
|
-
raise ConfigurationNotLoaded.new("Configuration does not seem to be loaded. Plase call A9n.load
|
16
|
+
raise ConfigurationNotLoaded.new("Configuration does not seem to be loaded. Plase call `A9n.load`.")
|
16
17
|
end
|
17
18
|
|
18
19
|
def env
|
19
|
-
|
20
|
+
@env ||= ENV['RAILS_ENV'] || ENV['RACK_ENV'] || ENV['APP_ENV']
|
20
21
|
end
|
21
|
-
|
22
|
+
|
22
23
|
def local_app
|
23
|
-
|
24
|
+
@local_app ||= Rails
|
24
25
|
end
|
25
26
|
|
26
27
|
def local_app=(local_app)
|
27
|
-
|
28
|
+
@local_app = local_app
|
28
29
|
end
|
29
30
|
|
30
31
|
def load
|
@@ -45,7 +46,13 @@ module A9n
|
|
45
46
|
def load_yml(file)
|
46
47
|
path = File.join(local_app.root, file)
|
47
48
|
return unless File.exists?(path)
|
48
|
-
YAML.load_file(path)
|
49
|
+
yml = YAML.load_file(path)
|
50
|
+
|
51
|
+
if yml.key?(self.env)
|
52
|
+
return yml[self.env]
|
53
|
+
else
|
54
|
+
raise MissingConfigurationData.new("Configuration data for #{self.env} was not found in #{file}")
|
55
|
+
end
|
49
56
|
end
|
50
57
|
|
51
58
|
private
|
data/lib/a9n/version.rb
CHANGED
data/spec/a9n_spec.rb
CHANGED
@@ -6,16 +6,18 @@ describe A9n do
|
|
6
6
|
it 'raises error' do
|
7
7
|
expect {
|
8
8
|
described_class.local_app
|
9
|
-
}.to raise_error(NameError
|
9
|
+
}.to raise_error(NameError)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
context 'when custom non-rails app is being used' do
|
14
14
|
let(:local_app) { stub(:env => 'test', :root => 'local_app') }
|
15
|
-
before { described_class.local_app = local_app}
|
15
|
+
before { described_class.local_app = local_app }
|
16
16
|
|
17
17
|
specify { described_class.local_app.should == local_app }
|
18
18
|
end
|
19
|
+
|
20
|
+
after { described_class.local_app = nil }
|
19
21
|
end
|
20
22
|
|
21
23
|
describe '.load' do
|
@@ -115,12 +117,25 @@ describe A9n do
|
|
115
117
|
end
|
116
118
|
|
117
119
|
context 'when file exists' do
|
118
|
-
before { described_class.should_receive(:env).and_return('test') }
|
119
120
|
let(:file_path) { 'fixtures/configuration.yml'}
|
121
|
+
before { described_class.should_receive(:env).twice.and_return(env) }
|
122
|
+
|
123
|
+
context 'and has data' do
|
124
|
+
let(:env) { 'test' }
|
125
|
+
|
126
|
+
it 'returns non-empty hash' do
|
127
|
+
subject.should be_kind_of(Hash)
|
128
|
+
subject.keys.should_not be_empty
|
129
|
+
end
|
130
|
+
end
|
131
|
+
context 'and has no data' do
|
132
|
+
let(:env) { 'production' }
|
120
133
|
|
121
|
-
|
122
|
-
|
123
|
-
|
134
|
+
it 'raises expection' do
|
135
|
+
expect {
|
136
|
+
subject
|
137
|
+
}.to raise_error(described_class::MissingConfigurationData)
|
138
|
+
end
|
124
139
|
end
|
125
140
|
end
|
126
141
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: a9n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-06 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Simple tool for managing app configuration
|
15
15
|
email:
|
@@ -19,6 +19,7 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- .gitignore
|
22
|
+
- .travis.yml
|
22
23
|
- Gemfile
|
23
24
|
- LICENSE
|
24
25
|
- README.md
|