flyml 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -4
- data/lib/flyml.rb +3 -32
- data/lib/flyml/configuration.rb +40 -0
- data/lib/flyml/values.rb +1 -1
- data/lib/flyml/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ede51d369e710a8baf7e06e11e897063ff2820ca
|
4
|
+
data.tar.gz: 25128f85465dff74556142b119c45bb50352313c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 785933acd29f64ca64815fb7015a650d872a9cb018840c1609cdb68782a77ee6571be4a5cbf30a308b56653cfaa082be566cd623b8d954b95463b12ea9c55da2
|
7
|
+
data.tar.gz: 3c87a5657867b50659037c3a075193238ae6ad643938c8a107d5a0092aa683a0bf52cd941a0afcdc3bd372e09a8a46712ff6f25f5badbae43f5215fb0f7eb05f
|
data/README.md
CHANGED
@@ -51,11 +51,10 @@ Here's how you would use Flyml:
|
|
51
51
|
```ruby
|
52
52
|
require 'flyml'
|
53
53
|
|
54
|
-
Flyml.env = 'development'
|
55
|
-
Flyml.root = '/path/to/project_root'
|
54
|
+
config = Flyml.config(root: '/path/to/project_root', env: Flyml.env = 'development')
|
56
55
|
|
57
|
-
|
58
|
-
|
56
|
+
config[:redis][:host] # 'dev.local'
|
57
|
+
config[:redis][:port] # 6379
|
59
58
|
```
|
60
59
|
|
61
60
|
## ToDo
|
data/lib/flyml.rb
CHANGED
@@ -1,39 +1,10 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'flyml/version'
|
3
|
+
require 'flyml/configuration'
|
3
4
|
require 'flyml/values'
|
4
5
|
|
5
6
|
module Flyml
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def [](file)
|
10
|
-
@config ||= {}
|
11
|
-
@config[file.to_sym] = load_settings(file) unless @config[file.to_sym]
|
12
|
-
@config[file.to_sym]
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def prepare_hash(data)
|
18
|
-
hash = data.is_a?(Hash) && data[env.to_s] ? data[env.to_s] : {}
|
19
|
-
Values.build(hash)
|
20
|
-
end
|
21
|
-
|
22
|
-
def file_path(name)
|
23
|
-
File.join(root, 'config', "#{name}.yml")
|
24
|
-
end
|
25
|
-
|
26
|
-
def load_settings(file)
|
27
|
-
path = file_path(file)
|
28
|
-
return unless File.exist?(path)
|
29
|
-
|
30
|
-
content = load_file_content(path)
|
31
|
-
data = YAML.load(content)
|
32
|
-
prepare_hash(data)
|
33
|
-
end
|
34
|
-
|
35
|
-
def load_file_content(path)
|
36
|
-
File.read(path)
|
37
|
-
end
|
7
|
+
def self.config(root:, env:)
|
8
|
+
Configuration.new(root, env)
|
38
9
|
end
|
39
10
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Flyml
|
2
|
+
class Configuration
|
3
|
+
attr_reader :root, :env
|
4
|
+
|
5
|
+
def initialize(root, env)
|
6
|
+
@root = root
|
7
|
+
@env = env
|
8
|
+
end
|
9
|
+
|
10
|
+
def [](file)
|
11
|
+
@config ||= {}
|
12
|
+
@config[file.to_sym] = load_settings(file) unless @config[file.to_sym]
|
13
|
+
@config[file.to_sym]
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def prepare_hash(data)
|
19
|
+
hash = data.is_a?(Hash) && data[env.to_s] ? data[env.to_s] : {}
|
20
|
+
Values.build(hash)
|
21
|
+
end
|
22
|
+
|
23
|
+
def file_path(name)
|
24
|
+
File.join(root, 'config', "#{name}.yml")
|
25
|
+
end
|
26
|
+
|
27
|
+
def load_settings(file)
|
28
|
+
path = file_path(file)
|
29
|
+
return unless File.exist?(path)
|
30
|
+
|
31
|
+
content = load_file_content(path)
|
32
|
+
data = YAML.load(content)
|
33
|
+
prepare_hash(data)
|
34
|
+
end
|
35
|
+
|
36
|
+
def load_file_content(path)
|
37
|
+
File.read(path)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/flyml/values.rb
CHANGED
data/lib/flyml/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flyml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- peerTransfer tech
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- bin/setup
|
100
100
|
- flyml.gemspec
|
101
101
|
- lib/flyml.rb
|
102
|
+
- lib/flyml/configuration.rb
|
102
103
|
- lib/flyml/core_ext/hash.rb
|
103
104
|
- lib/flyml/values.rb
|
104
105
|
- lib/flyml/version.rb
|