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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0fe20edb9ba83305578c4917bc1bf56669fd68b2
4
- data.tar.gz: db7863d9211bcdc8ebbc085de6eb5d4ad5c4818b
3
+ metadata.gz: ede51d369e710a8baf7e06e11e897063ff2820ca
4
+ data.tar.gz: 25128f85465dff74556142b119c45bb50352313c
5
5
  SHA512:
6
- metadata.gz: 2b76f265df05d57532a6d0a0a58b354fef3e82c565b4d6c2840babb96074c79117a48c1e0f83b150af4c2342298c61ca9188beba5446aae273422139d0caf727
7
- data.tar.gz: e2289e9773435ff89ccaffe06ced8c56b6576a8daffe88c8ec537cf2433b3d38aa0b7badc674c7ae6edb7b5352484b020d0893f9f255788ebec58f166bd59d85
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
- Flyml[:redis][:host] # 'dev.local'
58
- Flyml[:redis][:port] # 6379
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
- class << self
7
- attr_accessor :env, :root
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
@@ -41,4 +41,4 @@ module Flyml
41
41
  end
42
42
  alias write []=
43
43
  end
44
- end
44
+ end
data/lib/flyml/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Flyml
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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-13 00:00:00.000000000 Z
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