gem_config 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODkwYjliZTJjYjU2NDNlZDk5MmNlMTNiYmIxNGEyMWIzOGJlM2ViYg==
5
+ data.tar.gz: !binary |-
6
+ Y2E1MGNkZDk0MGRhYTFkNmViNmJiYWYwNjk1YWFkYjk2YzU0NmUzYw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZmQwZTRmYzNkOWY4NjRiZjliMDcxMmQ0YWFkYTBjMTM4ODYyZmIyYjg3NTk1
10
+ ZjRjNTI3OTY5YThhMTExNmU4MGNiODEzMjQ4NjdiYjNlMGE1ZmI5MjExYTRh
11
+ MGYzOTAyNDJhZmExZmQ4ZjNiYjhlMjkyYTEwNWYzYjYxOTRhNTQ=
12
+ data.tar.gz: !binary |-
13
+ YmU2MDEwYThkYWZlMjhmY2U3YmI2MjcwYzM4ZWU1NTQyM2Q4Y2VlMzlkZmMz
14
+ OGJlMmE3ZWQ1YjVmZTBkM2YxZjI0ZTZjNzBhYzI3YThjZTI3ODRiYThkNjE1
15
+ ZTY3ZWM0YTJmMWM1OGQ2MDU3ZTcxZTlmMWNkMjkxZThkYmU3ZGU=
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org/'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 kraut computing UG (haftungsbeschränkt)
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,34 @@
1
+ # GemConfig
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/gem_config.png)](http://badge.fury.io/rb/gem_config)
4
+ [![Build Status](https://secure.travis-ci.org/krautcomputing/gem_config.png)](http://travis-ci.org/krautcomputing/gem_config)
5
+ [![Dependency Status](https://gemnasium.com/krautcomputing/gem_config.png)](https://gemnasium.com/krautcomputing/gem_config)
6
+ [![Code Climate](https://codeclimate.com/github/krautcomputing/gem_config.png)](https://codeclimate.com/github/krautcomputing/gem_config)
7
+
8
+ A nifty way to make your gem configurable.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'gem_config'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install gem_config
23
+
24
+ ## Usage
25
+
26
+ ## TODO
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
@@ -0,0 +1,21 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'gem_config/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'gem_config'
8
+ gem.version = GemConfig::VERSION
9
+ gem.platform = Gem::Platform::RUBY
10
+ gem.authors = ['Manuel Meurer']
11
+ gem.email = 'manuel.meurer@gmail.com'
12
+ gem.summary = 'A nifty way to make your gem configurable.'
13
+ gem.description = 'A nifty way to make your gem configurable.'
14
+ gem.homepage = 'https://github.com/krautcomputing/gem_config'
15
+ gem.license = 'MIT'
16
+
17
+ gem.files = `git ls-files`.split($/)
18
+ gem.executables = gem.files.grep(%r(^bin/)).map { |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r(^(test|spec|features)/))
20
+ gem.require_paths = ['lib']
21
+ end
@@ -0,0 +1,6 @@
1
+ module GemConfig
2
+ end
3
+
4
+ require 'gem_config/configuration_rules'
5
+ require 'gem_config/configuration'
6
+ require 'gem_config/base'
@@ -0,0 +1,27 @@
1
+ module GemConfig
2
+ module Base
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ def configure
9
+ yield configuration
10
+ end
11
+
12
+ def configuration
13
+ @configuration ||= Configuration.new(configuration_rules)
14
+ end
15
+
16
+ def with_configuration(&block)
17
+ configuration_rules.instance_eval(&block)
18
+ end
19
+
20
+ private
21
+
22
+ def configuration_rules
23
+ @configuration_rules ||= ConfigurationRules.new
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,44 @@
1
+ module GemConfig
2
+ class Configuration
3
+ def initialize(configuration_rules)
4
+ @configuration_rules = configuration_rules
5
+ end
6
+
7
+ def rules
8
+ @configuration_rules
9
+ end
10
+
11
+ def current
12
+ @configuration_rules.keys.each_with_object({}) do |key, hash|
13
+ hash[key] = get(key)
14
+ end
15
+ end
16
+
17
+ def reset
18
+ @configuration_rules.keys.each do |key|
19
+ set key, nil
20
+ end
21
+ end
22
+
23
+ def method_missing(method, *args, &block)
24
+ case
25
+ when @configuration_rules.keys.include?(method.to_sym)
26
+ get method
27
+ when (match = method.to_s.match(/\A(?<key>\w+)=\z/)) && @configuration_rules.keys.include?(match[:key].to_sym)
28
+ set match[:key], args.first
29
+ else
30
+ super method, *args, block
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def set(key, value)
37
+ self.instance_variable_set "@#{key}", value
38
+ end
39
+
40
+ def get(key)
41
+ self.instance_variable_get("@#{key}") || @configuration_rules[key.to_sym][:default]
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,7 @@
1
+ module GemConfig
2
+ class ConfigurationRules < Hash
3
+ def has(key, attrs = {})
4
+ self[key.to_sym] = attrs
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module GemConfig
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem_config
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Manuel Meurer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A nifty way to make your gem configurable.
14
+ email: manuel.meurer@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - Gemfile
20
+ - LICENSE.txt
21
+ - README.md
22
+ - gem_config.gemspec
23
+ - lib/gem_config.rb
24
+ - lib/gem_config/base.rb
25
+ - lib/gem_config/configuration.rb
26
+ - lib/gem_config/configuration_rules.rb
27
+ - lib/gem_config/version.rb
28
+ homepage: https://github.com/krautcomputing/gem_config
29
+ licenses:
30
+ - MIT
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 2.0.3
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: A nifty way to make your gem configurable.
52
+ test_files: []