micro_config 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yaml ADDED
@@ -0,0 +1,2 @@
1
+ Metrics/LineLength:
2
+ Max: 132
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at jjuarez@tuenti.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in micro_config.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Javier Juarez
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # MicroConfig
2
+
3
+ The purpose of the little gem is to provide a basic way to support YAML configuration in standalone applications
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'micro_config'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install micro_config
20
+
21
+ ## Usage
22
+
23
+ #### Configure your application from a block
24
+ ```ruby
25
+ require 'micro_config'
26
+
27
+ # Configure a bunch of keys in a block
28
+ MicroConfig.configure do |config|
29
+ config.key = 'My value'
30
+ config.another_key = 'Another value'
31
+ #...
32
+ end
33
+
34
+ # Test these keys
35
+ MicroConfig.key?
36
+ MicroConfig.this_not_exist?
37
+
38
+ # Set new values for your keys
39
+ MicroConfig.key = 'The new value'
40
+
41
+ # Of course, complex values are allowed
42
+ MicroConfig.super_complex_config = Struct.new('Person', :name, :type)
43
+ ```
44
+
45
+ #### Configure your appication from a hash
46
+ ```ruby
47
+ require 'micro_config'
48
+
49
+ MicroConfig.configure(key: "Value", another_key: 'Other value')
50
+ ```
51
+ #### Configure your appication from a file
52
+ ```ruby
53
+ require 'micro_config'
54
+
55
+ MicroConfig.configure('/opt/my_app/config/application.yaml')
56
+ # and you can use the form of... you know
57
+ MicroConfig.configure('/opt/my_app/config/application.yaml', environment: :production)
58
+ ```
59
+ ## Development
60
+
61
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
62
+
63
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jjuarez/micro_config. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
68
+
69
+
70
+ ## License
71
+
72
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'micro_config'
5
+ require 'irb'
6
+
7
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ require 'micro_config/version'
2
+ require 'micro_config/micro_config'
3
+
@@ -0,0 +1,86 @@
1
+ # encoding:UTF-8
2
+ require 'yaml'
3
+
4
+ #
5
+ # = MicroConfig - support for a basic yaml configuration
6
+ module MicroConfig
7
+ extend self
8
+
9
+ @config = {}
10
+
11
+ def symbolize(object)
12
+ case object
13
+ when Hash
14
+ object.inject({}) do |memo, (k, v)|
15
+ memo.tap { |m| m[k.to_sym] = symbolize(v) }
16
+ end
17
+ when Array
18
+ object.map { |v| symbolize(v) }
19
+ else
20
+ object
21
+ end
22
+ end
23
+
24
+ def to_h
25
+ @config
26
+ end
27
+
28
+ def [](key)
29
+ @config[key]
30
+ end
31
+
32
+ def []=(key, value)
33
+ @config[key.to_sym] = symbolize(value)
34
+ end
35
+
36
+ def fetch(key, default = nil)
37
+ @config.fetch(key, default)
38
+ end
39
+
40
+ def configure(source = nil, options = {}, &_block)
41
+ if options[:environment]
42
+ case source
43
+ when /\.(yml|yaml)$/i
44
+ file_config = YAML.load_file(source)
45
+ environment_config = file_config.fetch(options[:environment].to_s)
46
+
47
+ @config.merge!(symbolize(environment_config))
48
+ when Hash
49
+ hash_config = source.fetch(options[:environment].to_s)
50
+
51
+ @config.merge!(symbolize(hash_config))
52
+ else
53
+ yield self if block_given?
54
+ end
55
+ else
56
+ case source
57
+ when /\.(yml|yaml)$/i
58
+ @config.merge!(symbolize(YAML.load_file(source)))
59
+ when Hash
60
+ @config.merge!(symbolize(source))
61
+ else
62
+ yield self if block_given?
63
+ end
64
+ end
65
+ rescue => ce
66
+ raise("Problems loading config source: #{source}: (#{ce.message})")
67
+ end
68
+
69
+ def method_missing(method, *arguments, &_block)
70
+ clean_method = method.to_s
71
+
72
+ case clean_method
73
+ when /(.+)=$/
74
+ key = clean_method.delete('=').to_sym
75
+ @config[key] = arguments.size == 1 ? arguments[0] : arguments
76
+ when /(.+)\?$/
77
+ key = clean_method.delete('?').to_sym
78
+
79
+ @config.keys.include?(key)
80
+ else
81
+ key = clean_method.to_sym
82
+
83
+ @config.fetch(key)
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,3 @@
1
+ module MicroConfig
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'micro_config/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'micro_config'
8
+ spec.version = MicroConfig::VERSION
9
+ spec.authors = ['Javier Juarez']
10
+ spec.email = ['javier.juarez@gmail.com']
11
+
12
+ spec.summary = 'A basic YAML config support'
13
+ spec.description = 'Basic YAML config support for standalone applications'
14
+ spec.homepage = 'https://github.com/jjuarez/micro_config'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.11'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
+ spec.add_development_dependency 'rubocop', '~> 0.30'
26
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: micro_config
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Javier Juarez
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2016-04-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.11'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.11'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '10.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '10.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rubocop
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '0.30'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '0.30'
78
+ description: Basic YAML config support for standalone applications
79
+ email:
80
+ - javier.juarez@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .rspec
87
+ - .rubocop.yaml
88
+ - .travis.yml
89
+ - CODE_OF_CONDUCT.md
90
+ - Gemfile
91
+ - LICENSE.txt
92
+ - README.md
93
+ - Rakefile
94
+ - bin/console
95
+ - bin/setup
96
+ - lib/micro_config.rb
97
+ - lib/micro_config/micro_config.rb
98
+ - lib/micro_config/version.rb
99
+ - micro_config.gemspec
100
+ homepage: https://github.com/jjuarez/micro_config
101
+ licenses:
102
+ - MIT
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ segments:
114
+ - 0
115
+ hash: -889162790603899199
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ segments:
123
+ - 0
124
+ hash: -889162790603899199
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 1.8.30
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: A basic YAML config support
131
+ test_files: []