config-file 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzAzYmE5YmNmNWU0ZmVmNGQ3NmU1MGE2NjJlNWZhNTM3ZmIxMTIwMA==
5
+ data.tar.gz: !binary |-
6
+ ZTRjN2I4YWI2NTcxNGViM2EyNTM5MDlkNmZmYTNkNjZkMmIxZjY5Ng==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OTNiMTNlMTQzODU1MzRkYWM3NzY1ODQ4OWM0NDk0N2ZiNWM0MjZkOTA0MzFj
10
+ ZWM3MGUxMDhiNDk0ZmQ5YjQ5MTcwN2JiNjRiOWNiNDE0OWJmNmY5Y2E1MjJj
11
+ NzhkNWNiODUzZTE3ZWQ5MGVhOWE0ZGQwYTRmYTVkMjQ3NjdjMzY=
12
+ data.tar.gz: !binary |-
13
+ ZWUzMDc3YmNhZTYyOGQ2M2Q4NzVjNGFmZTY5ZWE3YjRjZDQ5ZjA0NzcwZDFk
14
+ OWRkYTM1ZWRlODkyNzg2OTgwNjU0YzhjNDNiNTcxZGQ3MWMwZDE1NDU5YWYy
15
+ YmFlMGIxYzM2YzI0ODMxNmMxOTg3ZmRhOGY4MzMxYjcxMmUxMDc=
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/.idea/.rakeTasks ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Run RSpec code examples" fullCmd="spec" taksId="spec" /><RakeTask description="" fullCmd="build" taksId="build" /><RakeTask description="" fullCmd="gen" taksId="gen" /><RakeTask description="" fullCmd="install" taksId="install" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeTask description="" fullCmd="uninstall" taksId="uninstall" /></RakeGroup></Settings>
@@ -0,0 +1,28 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="FacetManager">
4
+ <facet type="gem" name="Ruby Gem">
5
+ <configuration>
6
+ <option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
7
+ <option name="GEM_APP_TEST_PATH" value="" />
8
+ <option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
9
+ </configuration>
10
+ </facet>
11
+ </component>
12
+ <component name="NewModuleRootManager">
13
+ <content url="file://$MODULE_DIR$" />
14
+ <orderEntry type="inheritedJdk" />
15
+ <orderEntry type="sourceFolder" forTests="false" />
16
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v1.7.4, RVM: ruby-1.9.3-p547) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, RVM: ruby-1.9.3-p547) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="file_utils (v1.0.7, RVM: ruby-1.9.3-p547) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="gemcutter (v0.7.1, RVM: ruby-1.9.3-p547) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="gemspec_deps_gen (v1.1.2, RVM: ruby-1.9.3-p547) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="json (v1.8.1, RVM: ruby-1.9.3-p547) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v3.1.0, RVM: ruby-1.9.3-p547) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.1.7, RVM: ruby-1.9.3-p547) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.1.2, RVM: ruby-1.9.3-p547) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.1.3, RVM: ruby-1.9.3-p547) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.1.2, RVM: ruby-1.9.3-p547) [gem]" level="application" />
27
+ </component>
28
+ </module>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
4
+ </project>
data/.idea/misc.xml ADDED
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-1.9.3-p547" project-jdk-type="RUBY_SDK" />
4
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/config-file.iml" filepath="$PROJECT_DIR$/.idea/config-file.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,5 @@
1
+ <component name="DependencyValidationManager">
2
+ <state>
3
+ <option name="SKIP_IMPORT_STATEMENTS" value="false" />
4
+ </state>
5
+ </component>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ config_file
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.4
data/CHANGES ADDED
@@ -0,0 +1,5 @@
1
+ = ConfigFile Changelog
2
+
3
+ == Version 1.0.0
4
+
5
+ * Initial release.
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :default do
4
+ gem "meta_methods"
5
+ gem "json"
6
+ end
7
+
8
+ group :development do
9
+ gem "gemspec_deps_gen"
10
+ gem "gemcutter"
11
+ end
12
+
13
+ group :test do
14
+ gem "rspec"
15
+ end
16
+
data/Gemfile.lock ADDED
@@ -0,0 +1,33 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.2.5)
5
+ file_utils (1.0.7)
6
+ gemcutter (0.7.1)
7
+ gemspec_deps_gen (1.1.2)
8
+ bundler
9
+ file_utils
10
+ json (1.8.1)
11
+ meta_methods (1.3.0)
12
+ rspec (3.1.0)
13
+ rspec-core (~> 3.1.0)
14
+ rspec-expectations (~> 3.1.0)
15
+ rspec-mocks (~> 3.1.0)
16
+ rspec-core (3.1.7)
17
+ rspec-support (~> 3.1.0)
18
+ rspec-expectations (3.1.2)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.1.0)
21
+ rspec-mocks (3.1.3)
22
+ rspec-support (~> 3.1.0)
23
+ rspec-support (3.1.2)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ gemcutter
30
+ gemspec_deps_gen
31
+ json
32
+ meta_methods
33
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Alexander Shvets
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.
22
+
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ config_file
2
+ ============
3
+
4
+ Simple library for reading configuration from different sources.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'config_file'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install config_file
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ require 'config_file'
24
+
25
+ configurator = ConfigFile.bew
26
+
27
+ config1 = configurator.load "spec/config/test_config.yaml"
28
+ config2 = configurator.load "spec/config/test_config.json"
29
+ config3 = configurator.load "spec/config/test_config.rb"
30
+ ```
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
39
+
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env rake
2
+
3
+ $LOAD_PATH.unshift File.expand_path("lib", File.dirname(__FILE__))
4
+
5
+ require "rspec/core/rake_task"
6
+ require "config_file/version"
7
+ require "gemspec_deps_gen/gemspec_deps_gen"
8
+
9
+ version = ConfigFile::VERSION
10
+ project_name = File.basename(Dir.pwd)
11
+
12
+ task :gen do
13
+ generator = GemspecDepsGen.new
14
+
15
+ generator.generate_dependencies "spec", "#{project_name}.gemspec.erb", "#{project_name}.gemspec"
16
+ end
17
+
18
+ task :build => :gen do
19
+ system "gem build #{project_name}.gemspec"
20
+ end
21
+
22
+ task :install do
23
+ system "gem install #{project_name}-#{version}.gem"
24
+ end
25
+
26
+ task :uninstall do
27
+ system "gem uninstall #{project_name}"
28
+ end
29
+
30
+ task :release => :build do
31
+ system "gem push #{project_name}-#{version}.gem"
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new do |task|
35
+ task.pattern = 'spec/**/*_spec.rb'
36
+ task.verbose = false
37
+ end
38
+
39
+
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/lib/config_file/version')
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "config-file"
7
+ spec.summary = %q{Simple library for reading configuration from different sources.}
8
+ spec.description = %q{Description: Simple library for reading configuration from different sources.}
9
+ spec.email = "alexander.shvets@gmail.com"
10
+ spec.authors = ["Alexander Shvets"]
11
+ spec.homepage = "http://github.com/shvets/config_file"
12
+
13
+ spec.files = `git ls-files`.split($\)
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+ spec.version = ConfigFile::VERSION
17
+ spec.license = "MIT"
18
+
19
+ <%= project_dependencies %>
20
+ end
21
+
@@ -0,0 +1 @@
1
+ require 'config_file/config_file'
@@ -0,0 +1,36 @@
1
+ require 'meta_methods/core'
2
+ require 'yaml'
3
+ require 'json'
4
+
5
+ class ConfigFile
6
+ YAML_EXT = '.yaml'
7
+ RUBY_EXT = '.rb'
8
+ JSON_EXT = 'json'
9
+
10
+ attr_reader :config
11
+
12
+ def load file_name, ext=nil
13
+ ext = File.extname(file_name) unless ext
14
+
15
+ @config = case ext
16
+ when YAML_EXT
17
+ YAML.load_file(File.expand_path(file_name))
18
+
19
+ when RUBY_EXT
20
+ content = File.open(file_name).read
21
+
22
+ MetaMethods::Core.instance.block_to_hash(content)
23
+
24
+ when JSON_EXT
25
+ content = File.open(file_name).read
26
+
27
+ JSON.parse(content)
28
+
29
+ else
30
+ content = File.open(file_name).read
31
+
32
+ JSON.parse(content)
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,3 @@
1
+ class ConfigFile
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ {
2
+ "property1": "value1",
3
+
4
+ "property2": {
5
+ "property21": "value21"
6
+ }
7
+ }
@@ -0,0 +1,3 @@
1
+ property1 = "value1"
2
+
3
+ property2 = {property21: "value21"}
@@ -0,0 +1,6 @@
1
+ property1:
2
+ value1
3
+
4
+ property2:
5
+ property21:
6
+ value21
@@ -0,0 +1,27 @@
1
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
+
3
+ require 'config_file'
4
+
5
+ describe ConfigFile do
6
+
7
+ it "reads from yaml" do
8
+ config = subject.load "spec/config/test_config.yaml"
9
+
10
+ expect(config['property1']).to eq "value1"
11
+ expect(config['property2']['property21']).to eq "value21"
12
+ end
13
+
14
+ it "reads from json" do
15
+ config = subject.load "spec/config/test_config.json"
16
+
17
+ expect(config['property1']).to eq "value1"
18
+ expect(config['property2']['property21']).to eq "value21"
19
+ end
20
+
21
+ it "reads from ruby fragment" do
22
+ config = subject.load "spec/config/test_config.rb"
23
+
24
+ expect(config[:property1]).to eq "value1"
25
+ expect(config[:property2][:property21]).to eq "value21"
26
+ end
27
+ end
@@ -0,0 +1 @@
1
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: config-file
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Shvets
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: meta_methods
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: gemspec_deps_gen
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gemcutter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ! 'Description: Simple library for reading configuration from different
70
+ sources.'
71
+ email: alexander.shvets@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .idea/.rakeTasks
78
+ - .idea/config-file.iml
79
+ - .idea/encodings.xml
80
+ - .idea/misc.xml
81
+ - .idea/modules.xml
82
+ - .idea/scopes/scope_settings.xml
83
+ - .idea/vcs.xml
84
+ - .ruby-gemset
85
+ - .ruby-version
86
+ - CHANGES
87
+ - Gemfile
88
+ - Gemfile.lock
89
+ - LICENSE
90
+ - README.md
91
+ - Rakefile
92
+ - config-file.gemspec.erb
93
+ - lib/config_file.rb
94
+ - lib/config_file/config_file.rb
95
+ - lib/config_file/version.rb
96
+ - spec/config/test_config.json
97
+ - spec/config/test_config.rb
98
+ - spec/config/test_config.yaml
99
+ - spec/configurator_spec.rb
100
+ - spec/spec_helper.rb
101
+ homepage: http://github.com/shvets/config_file
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.2.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Simple library for reading configuration from different sources.
125
+ test_files:
126
+ - spec/config/test_config.json
127
+ - spec/config/test_config.rb
128
+ - spec/config/test_config.yaml
129
+ - spec/configurator_spec.rb
130
+ - spec/spec_helper.rb