figi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5567063a6f470027f7f02a805aa86e68ffe680c5579adeddadccc7274637e434
4
+ data.tar.gz: f3dee70a950f553e9892b265cc3415b9c6bf6b52ae307a634f937a34508fca54
5
+ SHA512:
6
+ metadata.gz: 448f56d87f7b147e697a6bd362f66bb245fef5f3429ddc6e9706a10dfe0a6937180a4a638f68ebc9c75d35aa49dbf046cf9d920b72efec2235a4d44a0ba2897d
7
+ data.tar.gz: 24cf0ce537fcea387bcc2a37980378c2ec1cfbfecc6375a26546fefaf905d6956c852eb591b3921b3b21faca5686035ba85e95e25b7d77e036ee154a5c970106
@@ -0,0 +1,2 @@
1
+ .idea/
2
+ Gemfile.lock
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 ztz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # FIGI
2
+
3
+ FIGI is a super simple configuration library you can use in your ruby application.
4
+
5
+ ```ruby
6
+ require 'figi'
7
+
8
+ # config once
9
+ Figi::Config.load(environment: 'production', username: 'root')
10
+
11
+ # then use everywhere
12
+ puts(figi.environment) # => production
13
+ puts(figi.username) # => root
14
+
15
+ # also support loading from json or yaml file
16
+ Figi::Config.from_json('config/config.json')
17
+ Figi::Config.from_yaml('config/config.yml')
18
+
19
+ figi.environment = 'development'
20
+ puts(figi.environment) # => development
21
+
22
+ # nested access
23
+ figi.db = {
24
+ host: 'localhost',
25
+ port: 27017
26
+ }
27
+ puts(figi.db.host) # => localhost
28
+ puts(figi.db.port) # => 27017
29
+ ```
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.join(__dir__, 'lib')))
2
+ require 'figi/version'
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'figi'
6
+ gem.version = Figi::Version.to_s
7
+ gem.date = '2018-11-12'
8
+ gem.authors = ['ztz']
9
+ gem.email = ['hi_ztz@protonmail.com']
10
+ gem.description = 'Figi is a simple and easy ruby config library'
11
+ gem.summary = 'Easy config library'
12
+ gem.homepage = 'https://github.com/zt2/figi'
13
+ gem.license = 'MIT'
14
+
15
+ gem.files = `git ls-files`.split
16
+ gem.require_paths = ['lib']
17
+ gem.add_runtime_dependency 'hashie', '~> 3.6'
18
+ end
@@ -0,0 +1,16 @@
1
+ #
2
+ # Figi base module
3
+ #
4
+ module Figi
5
+ require_relative 'figi/config'
6
+ require_relative 'figi/version'
7
+ end
8
+
9
+ #
10
+ # Support global access
11
+ #
12
+ module Kernel
13
+ def figi
14
+ Figi::Config.instance
15
+ end
16
+ end
@@ -0,0 +1,87 @@
1
+ #
2
+ # Standard library
3
+ #
4
+ require 'forwardable'
5
+ require 'json'
6
+ require 'singleton'
7
+ require 'yaml'
8
+
9
+ #
10
+ # Third party library
11
+ #
12
+ require 'hashie'
13
+
14
+ module Figi
15
+ #
16
+ # Core class
17
+ #
18
+ class Config
19
+ extend Forwardable
20
+ include Singleton
21
+
22
+ class << self
23
+ # Load config from json file
24
+ #
25
+ # @param path [String] File path
26
+ # @example
27
+ # Figi::Config.from_json('config/config.json')
28
+ def from_json(path)
29
+ instance._figi_load(JSON.parse(File.read(path)))
30
+ end
31
+
32
+ # Load config from yaml file
33
+ #
34
+ # @param path[String] File path
35
+ # @example
36
+ # Figi::Config.from_yaml('config/config.yml')
37
+ def from_yaml(path)
38
+ instance._figi_load(YAML.safe_load(File.read(path)))
39
+ end
40
+
41
+ # Load config from hash
42
+ #
43
+ # @param config [Hash] Config
44
+ # @example
45
+ # Figi::Config.load(host: 'localhost', port: '27017')
46
+ # figi.host
47
+ # # => localhost
48
+ #
49
+ # Figi::Config.load do |config|
50
+ # config.host = 'localhost'
51
+ # config.port = '27017'
52
+ # end
53
+ # figi.host
54
+ # # => localhost
55
+ def load(config = {}, &block)
56
+ instance._figi_load(config, &block)
57
+ end
58
+ end
59
+
60
+ # Constructor
61
+ #
62
+ def initialize
63
+ @table = Hashie::Mash.new
64
+ end
65
+
66
+ # Load config from hash, don't use this directly
67
+ #
68
+ # @param config [Hash] Config
69
+ def _figi_load(config = {})
70
+ if @table.nil?
71
+ @table = Hashie::Mash.new(config)
72
+ else
73
+ @table.update(config)
74
+ end
75
+
76
+ yield @table if block_given?
77
+ end
78
+
79
+ # Dispatch to Hashie::Mash
80
+ #
81
+ def method_missing(mid, *args)
82
+ @table.send(mid, *args)
83
+ end
84
+
85
+ def_delegators :@table, :inspect, :to_json, :to_h, :to_yaml, :to_s
86
+ end
87
+ end
@@ -0,0 +1,17 @@
1
+ module Figi
2
+ #
3
+ # Version
4
+ #
5
+ module Version
6
+
7
+ MAJOR = '0'.freeze
8
+ MINOR = '1'.freeze
9
+ PATCH = '0'.freeze
10
+
11
+ class << self
12
+ def to_s
13
+ "#{MAJOR}.#{MINOR}.#{PATCH}"
14
+ end
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: figi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ztz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashie
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.6'
27
+ description: Figi is a simple and easy ruby config library
28
+ email:
29
+ - hi_ztz@protonmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - LICENSE
36
+ - README.md
37
+ - figi.gemspec
38
+ - lib/figi.rb
39
+ - lib/figi/config.rb
40
+ - lib/figi/version.rb
41
+ homepage: https://github.com/zt2/figi
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.7.7
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Easy config library
65
+ test_files: []