econfig 0.1.0 → 0.1.1
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 +7 -0
- data/econfig.gemspec +1 -0
- data/lib/econfig.rb +7 -0
- data/lib/econfig/active_record.rb +1 -7
- data/lib/econfig/memory.rb +9 -8
- data/lib/econfig/rails.rb +3 -1
- data/lib/econfig/version.rb +1 -1
- data/lib/econfig/yaml.rb +11 -2
- data/spec/configuration_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -0
- data/spec/yaml_spec.rb +2 -2
- metadata +19 -29
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a7e3bc4fa45ea6ef51d0dce442bf13f51d2d4ba4
|
4
|
+
data.tar.gz: d870600bc13249713c6b91ac7e5a92a74cbf1537
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b1145170d7baccae21942224722b5c8efd02315133a7d8179c545fdd0f6b0288d11f93412b93c7ff02029b66976bd789fb7e85a2f7d09a301cae27cd6d5ce837
|
7
|
+
data.tar.gz: cee5b2354df7abf3185749e9805873747b241b8264e12e4cc96e4d87c5e457887f6c684ef2874c9ff98b2bec894ff634dff85ffc4fd0fbf754e97f1c3f7a2584
|
data/econfig.gemspec
CHANGED
@@ -11,6 +11,7 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.description = %q{Flexible configuration for Ruby/Rails applications with a variety of backends}
|
12
12
|
gem.summary = %q{Congifure Ruby apps}
|
13
13
|
gem.homepage = "https://github.com/elabs/econfig"
|
14
|
+
gem.license = "MIT"
|
14
15
|
|
15
16
|
gem.files = `git ls-files`.split($/)
|
16
17
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
data/lib/econfig.rb
CHANGED
@@ -7,6 +7,7 @@ require "econfig/shortcut"
|
|
7
7
|
|
8
8
|
module Econfig
|
9
9
|
class NotFound < StandardError; end
|
10
|
+
class UninitializedError < StandardError; end
|
10
11
|
|
11
12
|
class << self
|
12
13
|
attr_accessor :root, :env, :instance
|
@@ -20,6 +21,12 @@ module Econfig
|
|
20
21
|
require "econfig/redis"
|
21
22
|
Econfig.instance.backends << Econfig::Redis.new(redis)
|
22
23
|
end
|
24
|
+
|
25
|
+
def init
|
26
|
+
Econfig.instance.backends.each do |backend|
|
27
|
+
backend.init if backend.respond_to?(:init)
|
28
|
+
end
|
29
|
+
end
|
23
30
|
end
|
24
31
|
end
|
25
32
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Econfig
|
2
2
|
class ActiveRecord
|
3
3
|
class Option < ::ActiveRecord::Base
|
4
|
-
attr_accessible :key, :value
|
4
|
+
attr_accessible :key, :value rescue nil
|
5
5
|
self.table_name = "econfig_options"
|
6
6
|
validates_uniqueness_of :key
|
7
7
|
validates_presence_of :key
|
@@ -15,11 +15,5 @@ module Econfig
|
|
15
15
|
option = Option.where(:key => key).first_or_initialize
|
16
16
|
option.update_attributes!(:value => value)
|
17
17
|
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def options
|
22
|
-
@options ||= {}
|
23
|
-
end
|
24
18
|
end
|
25
19
|
end
|
data/lib/econfig/memory.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
module Econfig
|
2
2
|
class Memory
|
3
|
-
def
|
4
|
-
|
3
|
+
def initialize
|
4
|
+
@mutex = Mutex.new
|
5
|
+
@options = {}
|
5
6
|
end
|
6
7
|
|
7
|
-
def
|
8
|
-
options[key]
|
8
|
+
def get(key)
|
9
|
+
@options[key]
|
9
10
|
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def set(key, value)
|
13
|
+
@mutex.synchronize do
|
14
|
+
@options[key] = value
|
15
|
+
end
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
data/lib/econfig/rails.rb
CHANGED
@@ -3,10 +3,12 @@ require "econfig"
|
|
3
3
|
|
4
4
|
module Econfig
|
5
5
|
class Railtie < Rails::Railtie
|
6
|
-
initializer "econfig.setup" do
|
6
|
+
initializer "econfig.setup", before: :load_environment_config do
|
7
7
|
Econfig.root = Rails.root
|
8
8
|
Econfig.env = Rails.env
|
9
9
|
Rails.application.config.app = Econfig.instance
|
10
|
+
|
11
|
+
Econfig.init
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
data/lib/econfig/version.rb
CHANGED
data/lib/econfig/yaml.rb
CHANGED
@@ -5,7 +5,16 @@ module Econfig
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def get(key)
|
8
|
-
options[key]
|
8
|
+
options[key]
|
9
|
+
end
|
10
|
+
|
11
|
+
def init
|
12
|
+
require "yaml"
|
13
|
+
if File.exist?(path)
|
14
|
+
@options = ::YAML.load_file(path)[Econfig.env]
|
15
|
+
else
|
16
|
+
@options = {}
|
17
|
+
end
|
9
18
|
end
|
10
19
|
|
11
20
|
private
|
@@ -15,7 +24,7 @@ module Econfig
|
|
15
24
|
end
|
16
25
|
|
17
26
|
def options
|
18
|
-
@options
|
27
|
+
@options or raise Econfig::UninitializedError
|
19
28
|
end
|
20
29
|
end
|
21
30
|
end
|
data/spec/configuration_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/yaml_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
describe Econfig::YAML do
|
2
|
-
let(:backend) { Econfig::YAML.new }
|
2
|
+
let(:backend) { Econfig::YAML.new.tap(&:init) }
|
3
3
|
describe "#get" do
|
4
4
|
it "fetches option from yaml config file" do
|
5
5
|
backend.get("quox").should == "baz"
|
@@ -10,7 +10,7 @@ describe Econfig::YAML do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "returns nil when there is no config file" do
|
13
|
-
backend = Econfig::YAML.new("/does/not/exist")
|
13
|
+
backend = Econfig::YAML.new("/does/not/exist").tap(&:init)
|
14
14
|
backend.get("does_not_exist").should be_nil
|
15
15
|
end
|
16
16
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: econfig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jonas Nicklas
|
@@ -10,70 +9,62 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2014-04-01 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: rspec
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
|
-
- -
|
18
|
+
- - ">="
|
21
19
|
- !ruby/object:Gem::Version
|
22
20
|
version: '0'
|
23
21
|
type: :development
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
|
-
- -
|
25
|
+
- - ">="
|
29
26
|
- !ruby/object:Gem::Version
|
30
27
|
version: '0'
|
31
28
|
- !ruby/object:Gem::Dependency
|
32
29
|
name: activerecord
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
31
|
requirements:
|
36
|
-
- -
|
32
|
+
- - ">="
|
37
33
|
- !ruby/object:Gem::Version
|
38
34
|
version: '0'
|
39
35
|
type: :development
|
40
36
|
prerelease: false
|
41
37
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
38
|
requirements:
|
44
|
-
- -
|
39
|
+
- - ">="
|
45
40
|
- !ruby/object:Gem::Version
|
46
41
|
version: '0'
|
47
42
|
- !ruby/object:Gem::Dependency
|
48
43
|
name: sqlite3
|
49
44
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
45
|
requirements:
|
52
|
-
- -
|
46
|
+
- - ">="
|
53
47
|
- !ruby/object:Gem::Version
|
54
48
|
version: '0'
|
55
49
|
type: :development
|
56
50
|
prerelease: false
|
57
51
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
52
|
requirements:
|
60
|
-
- -
|
53
|
+
- - ">="
|
61
54
|
- !ruby/object:Gem::Version
|
62
55
|
version: '0'
|
63
56
|
- !ruby/object:Gem::Dependency
|
64
57
|
name: redis
|
65
58
|
requirement: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
59
|
requirements:
|
68
|
-
- -
|
60
|
+
- - ">="
|
69
61
|
- !ruby/object:Gem::Version
|
70
62
|
version: '0'
|
71
63
|
type: :development
|
72
64
|
prerelease: false
|
73
65
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
66
|
requirements:
|
76
|
-
- -
|
67
|
+
- - ">="
|
77
68
|
- !ruby/object:Gem::Version
|
78
69
|
version: '0'
|
79
70
|
description: Flexible configuration for Ruby/Rails applications with a variety of
|
@@ -85,8 +76,8 @@ executables: []
|
|
85
76
|
extensions: []
|
86
77
|
extra_rdoc_files: []
|
87
78
|
files:
|
88
|
-
- .gitignore
|
89
|
-
- .rspec
|
79
|
+
- ".gitignore"
|
80
|
+
- ".rspec"
|
90
81
|
- Gemfile
|
91
82
|
- LICENSE.txt
|
92
83
|
- README.md
|
@@ -115,28 +106,28 @@ files:
|
|
115
106
|
- spec/spec_helper.rb
|
116
107
|
- spec/yaml_spec.rb
|
117
108
|
homepage: https://github.com/elabs/econfig
|
118
|
-
licenses:
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
119
112
|
post_install_message:
|
120
113
|
rdoc_options: []
|
121
114
|
require_paths:
|
122
115
|
- lib
|
123
116
|
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
-
none: false
|
125
117
|
requirements:
|
126
|
-
- -
|
118
|
+
- - ">="
|
127
119
|
- !ruby/object:Gem::Version
|
128
120
|
version: '0'
|
129
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
-
none: false
|
131
122
|
requirements:
|
132
|
-
- -
|
123
|
+
- - ">="
|
133
124
|
- !ruby/object:Gem::Version
|
134
125
|
version: '0'
|
135
126
|
requirements: []
|
136
127
|
rubyforge_project:
|
137
|
-
rubygems_version:
|
128
|
+
rubygems_version: 2.2.2
|
138
129
|
signing_key:
|
139
|
-
specification_version:
|
130
|
+
specification_version: 4
|
140
131
|
summary: Congifure Ruby apps
|
141
132
|
test_files:
|
142
133
|
- spec/active_record_spec.rb
|
@@ -148,4 +139,3 @@ test_files:
|
|
148
139
|
- spec/shortcut_spec.rb
|
149
140
|
- spec/spec_helper.rb
|
150
141
|
- spec/yaml_spec.rb
|
151
|
-
has_rdoc:
|