bonfig 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
+ SHA1:
3
+ metadata.gz: 7468a2f0db5fdccd9d11b5d5872ec29e83243397
4
+ data.tar.gz: 1bd2eb2a5796cb20bad3968fe767b28ed9fc6905
5
+ SHA512:
6
+ metadata.gz: 2bc8e7d440dd490ce33ebedc07f3e5ca01739c6031b9eac32e2609c148a8e61d05329301724b822538c36709416ff6eaa3b9d3263abbc03e76f97d146ae898cc
7
+ data.tar.gz: 5868838988dbe7c409c2c95fdc1551de97b88b5910bf13fbb9ff0800430d3ea7f1086ee1b443156a111dcf8287571212de0869dd55cbe6659757649af1efd103
@@ -0,0 +1 @@
1
+ repo_token: wFwWApCvRT7srX8AbTakbUOzJCos4HvFw
@@ -0,0 +1,3 @@
1
+ -
2
+ ChangeLog.md
3
+ LICENSE.txt
@@ -0,0 +1,6 @@
1
+ Gemfile.lock
2
+ doc/
3
+ pkg/
4
+ coverage/
5
+ vendor/cache/*.gem
6
+ .bundle/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
@@ -0,0 +1,18 @@
1
+ Documentation:
2
+ Enabled: false
3
+
4
+ RedundantSelf:
5
+ Enabled: false
6
+
7
+ LineLength:
8
+ Max: 200
9
+
10
+ HashSyntax:
11
+ EnforcedStyle: ruby19
12
+
13
+ AllCops:
14
+ Includes:
15
+ - Gemfile
16
+ - Rakefile
17
+ Excludes:
18
+ - bin/**
@@ -0,0 +1 @@
1
+ bonfig
@@ -0,0 +1 @@
1
+ 2.0.0
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - jruby-19mode
@@ -0,0 +1 @@
1
+ --markup markdown --title "bonfig Documentation" --protected
@@ -0,0 +1,4 @@
1
+ ### 0.1.0 / 2014-03-02
2
+
3
+ * Initial release:
4
+
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'pry'
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'guard-rubocop'
10
+ gem 'gem-release'
11
+ gem 'coveralls', require: false
12
+ end
@@ -0,0 +1,10 @@
1
+ guard :rspec do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch('spec/spec_helper.rb') { "spec" }
4
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
5
+ end
6
+
7
+ guard :rubocop, all_on_start: true, cli: ['--auto-correct'] do
8
+ watch(%r{.+\.rb$})
9
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
10
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 George Erickson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,50 @@
1
+ # Bonfig
2
+ [![Build Status](https://travis-ci.org/GeorgeErickson/bonfig.png?branch=master)](https://travis-ci.org/GeorgeErickson/bonfig)
3
+ [![Code Climate](https://codeclimate.com/github/GeorgeErickson/bonfig.png)](https://codeclimate.com/github/GeorgeErickson/bonfig)
4
+ [![Coverage Status](https://coveralls.io/repos/GeorgeErickson/bonfig/badge.png?branch=master)](https://coveralls.io/r/GeorgeErickson/bonfig?branch=master)
5
+ [![Dependency Status](https://gemnasium.com/GeorgeErickson/bonfig.png)](https://gemnasium.com/GeorgeErickson/bonfig)
6
+
7
+
8
+ Simple configuration for modules.
9
+
10
+ ## Install
11
+ ```ruby
12
+ gem 'bonfig'
13
+ ```
14
+
15
+ ## Usage
16
+ ```ruby
17
+ module MyModule
18
+ extend Bonfig
19
+
20
+ bonfig do
21
+ config :index_name, default: 'test'
22
+ config :redis do
23
+ config :port, default: 6379
24
+ config :host, default: 'localhost'
25
+ config :db, default: 1
26
+ end
27
+ end
28
+ end
29
+
30
+
31
+ MyModule.config do |c|
32
+ c.index_name = 'dev'
33
+
34
+ c.redis = {port: 1234, host: '0.0.0.0' }
35
+ # Or
36
+ c.redis do |r|
37
+ r.port = 1234
38
+ r.host = '0.0.0.0'
39
+ end
40
+ # Or
41
+ c.redis.port = 1234
42
+ c.redis.host = '0.0.0.0'
43
+ end
44
+
45
+
46
+ puts MyModule.config.index_name # 'dev'
47
+ puts MyModule.config.redis.port # 1234
48
+ puts MyModule.config.redis.host # '0.0.0.0'
49
+ puts MyModule.config.redis.db # 1
50
+ ```
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+
5
+ begin
6
+ require 'bundler'
7
+ rescue LoadError => e
8
+ warn e.message
9
+ warn 'Run `gem install bundler` to install Bundler.'
10
+ exit(-1)
11
+ end
12
+
13
+ begin
14
+ Bundler.setup(:development)
15
+ rescue Bundler::BundlerError => e
16
+ warn e.message
17
+ warn 'Run `bundle install` to install missing gems.'
18
+ exit e.status_code
19
+ end
20
+
21
+ require 'rake'
22
+
23
+ require 'rubygems/tasks'
24
+ Gem::Tasks.new
25
+
26
+ require 'rspec/core/rake_task'
27
+ RSpec::Core::RakeTask.new
28
+
29
+ task test: :spec
30
+ task default: :spec
31
+
32
+ require 'yard'
33
+ YARD::Rake::YardocTask.new
34
+ task doc: :yard
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/bonfig/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "bonfig"
7
+ gem.version = Bonfig::VERSION
8
+ gem.summary = %q{A simple config mixin for gems.}
9
+ gem.description = %q{Configuration Mixin}
10
+ gem.license = "MIT"
11
+ gem.authors = ["George Erickson"]
12
+ gem.email = "george.erickson.jr@gmail.com"
13
+ gem.homepage = "https://github.com/GeorgeErickson/bonfig/"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ['lib']
18
+
19
+ gem.add_development_dependency 'bundler', '~> 1.0'
20
+ gem.add_development_dependency 'rake', '~> 0.8'
21
+ gem.add_development_dependency 'rspec', '~> 2.4'
22
+ gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
23
+ gem.add_development_dependency 'yard', '~> 0.8'
24
+ end
@@ -0,0 +1,67 @@
1
+ module Bonfig
2
+ class BlankConfig < BasicObject
3
+ def initialize(&block)
4
+ @_data = ::Hash.new
5
+ instance_eval(&block)
6
+ end
7
+
8
+ def config(name, options = {}, &block)
9
+ name = name.to_sym
10
+ if block
11
+ _nested(name, &block)
12
+ else
13
+ @_data[name] = options[:default]
14
+ define_method("#{name}=") { |value| @_data[name] = value }
15
+ define_method(name) { @_data[name] }
16
+ end
17
+
18
+ define_method("#{name}?") { @_data.key?(name) }
19
+ end
20
+
21
+ def [](key)
22
+ @_data[key]
23
+ end
24
+
25
+ protected
26
+
27
+ def _update(data)
28
+ @_data.update(data)
29
+ end
30
+
31
+ def _nested(name, &block)
32
+ nested = @_data[name] = BlankConfig.new(&block)
33
+
34
+ define_method(name) do |&b|
35
+ if b
36
+ b.call(nested)
37
+ else
38
+ @_data[name]
39
+ end
40
+ end
41
+
42
+ define_method("#{name}=") do |val|
43
+ if val.is_a?(::Hash)
44
+ nested._update(val)
45
+ else
46
+ fail 'Can\'t assign value to nested config.'
47
+ end
48
+ end
49
+ end
50
+
51
+ def define_method(name, &block)
52
+ name = name.to_sym
53
+ (class << self; self; end).class_eval do
54
+ define_method(name, &block)
55
+ end
56
+ end
57
+ end
58
+
59
+ def bonfig(&block)
60
+ @config ||= BlankConfig.new(&block)
61
+ end
62
+
63
+ def config(data = nil, &block)
64
+ yield(@config) if block_given?
65
+ @config
66
+ end
67
+ end
@@ -0,0 +1,4 @@
1
+ module Bonfig
2
+ # bonfig version
3
+ VERSION = '0.1.0'
4
+ end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ module Helper
4
+ def bonfig_subject(&block)
5
+ subject do
6
+ Module.new do
7
+ extend Bonfig
8
+ bonfig(&block)
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ RSpec.configure do |config|
15
+ config.extend Helper
16
+ end
17
+
18
+ PROTECTED_WORDS = [:size, :method_missing, :new]
19
+
20
+ describe Bonfig do
21
+ context 'simple' do
22
+ bonfig_subject do
23
+ config :name
24
+ config :name_default, default: 1
25
+ end
26
+
27
+ it 'uses a default if given or nil' do
28
+ expect(subject.config.name).to be_nil
29
+ expect(subject.config.name_default).to eq(1)
30
+ end
31
+
32
+ it 'allows overide' do
33
+ subject.config do |c|
34
+ c.name = 1
35
+ c.name_default = 2
36
+ end
37
+
38
+ expect(subject.config.name).to eq(1)
39
+ expect(subject.config.name_default).to eq(2)
40
+ end
41
+ end
42
+
43
+ context 'protected words should be valid configs' do
44
+ bonfig_subject do
45
+ PROTECTED_WORDS.each do |meth|
46
+ config meth, default: meth
47
+ end
48
+ end
49
+
50
+ PROTECTED_WORDS.each do |meth|
51
+ it meth.to_s do
52
+ expect(subject.config[meth]).to eq(meth)
53
+ end
54
+ end
55
+ end
56
+
57
+ context 'nested assignment' do
58
+ bonfig_subject do
59
+ config :redis do
60
+ config :port, default: 6379
61
+ config :host, default: 'localhost'
62
+ end
63
+ end
64
+
65
+ it 'allows nested block assignment' do
66
+ subject.config do |c|
67
+ c.redis do |r|
68
+ r.port = 1
69
+ end
70
+
71
+ expect(subject.config.redis.port).to eq(1)
72
+ expect(subject.config.redis.host).to eq('localhost')
73
+ end
74
+ end
75
+
76
+ it 'allows attribute assignment' do
77
+ subject.config do |c|
78
+ c.redis.port = 1
79
+ end
80
+
81
+ expect(subject.config.redis.port).to eq(1)
82
+ expect(subject.config.redis.host).to eq('localhost')
83
+ end
84
+
85
+ it 'allows hash assignment' do
86
+ subject.config do |c|
87
+ c.redis = { port: 1 }
88
+ end
89
+
90
+ expect(subject.config.redis.port).to eq(1)
91
+ expect(subject.config.redis.host).to eq('localhost')
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,4 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'bonfig'
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bonfig
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - George Erickson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubygems-tasks
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.8'
83
+ description: Configuration Mixin
84
+ email: george.erickson.jr@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - .coveralls.yml
90
+ - .document
91
+ - .gitignore
92
+ - .rspec
93
+ - .rubocop.yml
94
+ - .ruby-gemset
95
+ - .ruby-version
96
+ - .travis.yml
97
+ - .yardopts
98
+ - ChangeLog.md
99
+ - Gemfile
100
+ - Guardfile
101
+ - LICENSE.txt
102
+ - README.md
103
+ - Rakefile
104
+ - bonfig.gemspec
105
+ - lib/bonfig.rb
106
+ - lib/bonfig/version.rb
107
+ - spec/bonfig_spec.rb
108
+ - spec/spec_helper.rb
109
+ homepage: https://github.com/GeorgeErickson/bonfig/
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.2.2
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: A simple config mixin for gems.
133
+ test_files:
134
+ - spec/bonfig_spec.rb
135
+ - spec/spec_helper.rb
136
+ has_rdoc: