cogwheels 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c5ee70dfbd9dd92d4281567d1ba1ada1a5bb8a02
4
+ data.tar.gz: 0ce0a29503a912eb6d8f239957b001cee86df9a5
5
+ SHA512:
6
+ metadata.gz: 5ad807c8cb8d9af9bcbaf71aaa19a7a9fa6687694c159f7d1ffc202297f38884aedd82029a49721bb63cca3143afd3dad99e46a595b6f221765bf0019b37e7d4
7
+ data.tar.gz: a469ca79dede33cc0b176f29034d49b9e541f2bf598a604e9dfcf9f0f744011713c4768e755246742dc5fd57b24a1969ba984a6b3b0bfec2a5f4aaa39ffbc345
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Christopher Lutz
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.
data/README.md ADDED
@@ -0,0 +1,7 @@
1
+ [![Dependency Status](https://gemnasium.com/badges/github.com/chrisblutz/cogwheels.svg)](https://gemnasium.com/github.com/chrisblutz/cogwheels)
2
+ [![Linux Build Status](https://travis-ci.org/chrisblutz/cogwheels.svg?branch=master)](https://travis-ci.org/chrisblutz/cogwheels)
3
+ [![Inline docs](http://inch-ci.org/github/chrisblutz/cogwheels.svg?branch=master)](http://inch-ci.org/github/chrisblutz/cogwheels)
4
+ [![Test Coverage](https://codeclimate.com/github/chrisblutz/cogwheels/badges/coverage.svg)](https://codeclimate.com/github/chrisblutz/cogwheels/coverage)
5
+ [![Code Climate](https://codeclimate.com/github/chrisblutz/cogwheels/badges/gpa.svg)](https://codeclimate.com/github/chrisblutz/cogwheels)
6
+ # Cogwheels
7
+ **Cogwheels** is a work-in-progress configuration-loading library for Ruby.
@@ -0,0 +1,36 @@
1
+ module Cogwheels
2
+ # This class contains configuration information loaded from YAML sources
3
+ class Configuration
4
+ class ImmutableConfigurationError < StandardError
5
+ end
6
+
7
+ attr_reader :mutable
8
+
9
+ def initialize(hash, mutable = true)
10
+ @hash = hash
11
+ @mutable = mutable
12
+ end
13
+
14
+ def [](key)
15
+ @hash[key]
16
+ end
17
+
18
+ def []=(key, value)
19
+ unless @mutable
20
+ error = <<-EOF
21
+ A modification was attempted on an immutable Configuration instance.
22
+ EOF
23
+ raise ImmutableConfigurationError, error
24
+ end
25
+ @hash[key] = value if @mutable
26
+ end
27
+
28
+ def to_s
29
+ @hash.to_s
30
+ end
31
+
32
+ def inspect
33
+ "Cogwheels::Configuration =>\n#{@hash}"
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,30 @@
1
+ require 'yaml'
2
+ require 'safe_yaml'
3
+
4
+ require 'cogwheels/configuration'
5
+
6
+ module Cogwheels
7
+ # This module helps in loading YAML configurations from different source types
8
+ module Loader
9
+ class << self
10
+ def load(src, mutable = true)
11
+ return Configuration.new(from_file(src), mutable) if File.file?(src)
12
+ end
13
+
14
+ def from_file(file)
15
+ hash = {}
16
+ if File.exist?(file)
17
+ yaml = IO.read(file)
18
+ hash = safe_load(yaml, File.path(file))
19
+ end
20
+ hash
21
+ end
22
+
23
+ private
24
+
25
+ def safe_load(yaml, name)
26
+ SafeYAML.load(yaml, name)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Cogwheels
2
+ VERSION = '0.1.1'.freeze
3
+ end
data/lib/cogwheels.rb ADDED
@@ -0,0 +1,39 @@
1
+ $LOAD_PATH.unshift(File.dirname(File.realpath(__FILE__)) + '/../lib')
2
+
3
+ # Internal dependencies
4
+ require 'cogwheels/version'
5
+
6
+ # Cogwheels allows YAML configuration files to be loaded into Configuration
7
+ # instances for ease of use
8
+ #
9
+ # Cogwheels is licensed under the MIT license:
10
+ #
11
+ # Copyright (c) 2016 Christopher Lutz
12
+ #
13
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ # of this software and associated documentation files (the "Software"), to deal
15
+ # in the Software without restriction, including without limitation the rights
16
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ # copies of the Software, and to permit persons to whom the Software is
18
+ # furnished to do so, subject to the following conditions:
19
+ #
20
+ # The above copyright notice and this permission notice shall be included in all
21
+ # copies or substantial portions of the Software.
22
+ #
23
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ # SOFTWARE.
30
+ module Cogwheels
31
+ autoload :Configuration, 'cogwheels/configuration'
32
+ autoload :Loader, 'cogwheels/loader'
33
+
34
+ module_function
35
+
36
+ def load(src, mutable = true)
37
+ Cogwheels::Loader.load(src, mutable)
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cogwheels
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Christopher Lutz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: safe_yaml
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ description: Cogwheels is a library to load configurations from YAML files into easy-to-use
28
+ hash-like objects
29
+ email:
30
+ - lutzblox@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE.txt
36
+ - README.md
37
+ - lib/cogwheels.rb
38
+ - lib/cogwheels/configuration.rb
39
+ - lib/cogwheels/loader.rb
40
+ - lib/cogwheels/version.rb
41
+ homepage: https://github.com/chrisblutz/cogwheels
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: '1.9'
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.6.6
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: A Ruby configuration-loading library
65
+ test_files: []