class_config 0.0.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: 923ca6ca0dfd7c952c25ecb6cfafd789a90b8887
4
+ data.tar.gz: 060ea7f2f395699ec26df9a364ef0146597f6069
5
+ SHA512:
6
+ metadata.gz: 5e4dec622d7b3cb141efd02fea27120f04ca631f9e95c0ce43e00c95b13225b1cecd86aac7edad7591adf00b87e2a36ee0ae3690d9c7d068a4ab6d513ece560b
7
+ data.tar.gz: 1aaa88e38b643f49f179a9123a6a067575d2efef8266897d0d99faf2226a27573563265e9cc299491dfe747b0c499013265938cee6791a577d275b32dab7f58e
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ coverage
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in class_config.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Gabriel Naiman
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.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # ClassConfig
2
+
3
+ Class configuration attributes
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'class_config'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install class_config
18
+
19
+ ## Usage
20
+
21
+ class MyClass
22
+ extend ClassConfig
23
+ attr_config :with_default, 'default value'
24
+ attr_config :without_default
25
+ attr_config :setting
26
+ end
27
+
28
+ MyClass.configure do |config|
29
+ config.setting = 'configuration value'
30
+ end
31
+
32
+ MyClass.setting # => 'configuration value'
33
+
34
+ MyClass.configuration # => {with_default: 'default value', without_default: nil, setting: 'configuration value'}
35
+
36
+ MyClass.restore_default_configuration
37
+
38
+ MyClass.configuration # => {with_default: 'default value', without_default: nil, setting: nil}
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:spec) do |t|
5
+ t.libs << 'spec'
6
+ t.pattern = 'spec/**/*_spec.rb'
7
+ t.verbose = false
8
+ end
9
+
10
+ task :console do
11
+ require 'pry'
12
+ require 'class_config'
13
+ ARGV.clear
14
+ Pry.start
15
+ end
16
+
17
+ task default: :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'class_config'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "class_config"
8
+ spec.version = ClassConfig::VERSION
9
+ spec.authors = ["Gabriel Naiman"]
10
+ spec.email = ["gabynaiman@gmail.com"]
11
+ spec.description = 'Class configuration attributes'
12
+ spec.summary = 'Class configuration attributes'
13
+ spec.homepage = 'https://github.com/gabynaiman/class_config'
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'minitest', '~> 4.7'
24
+ spec.add_development_dependency 'turn', '~> 0.9'
25
+ spec.add_development_dependency 'simplecov'
26
+ spec.add_development_dependency 'pry'
27
+ end
@@ -0,0 +1,38 @@
1
+ module ClassConfig
2
+
3
+ VERSION = '0.0.1'
4
+
5
+ alias_method :configure, :tap
6
+
7
+ def attr_config(name, default_value=nil)
8
+ configuration_defaults[name.to_sym] = default_value
9
+
10
+ define_singleton_method name do
11
+ configuration[name.to_sym]
12
+ end
13
+
14
+ define_singleton_method "#{name}=" do |value|
15
+ configuration_values[name.to_sym] = value
16
+ end
17
+ end
18
+
19
+ def configuration
20
+ configuration_defaults.merge configuration_values
21
+ end
22
+
23
+ def restore_default_configuration
24
+ configuration_values.clear
25
+ end
26
+
27
+ private
28
+
29
+ def configuration_defaults
30
+ @configuration_defaults ||= {}
31
+ end
32
+
33
+ def configuration_values
34
+ @configuration_values ||= {}
35
+ end
36
+
37
+
38
+ end
@@ -0,0 +1,58 @@
1
+ require 'minitest_helper'
2
+
3
+ describe ClassConfig do
4
+
5
+ class Configurable
6
+ extend ClassConfig
7
+ attr_config :with_default, 'default value'
8
+ attr_config :without_default
9
+ attr_config :setting
10
+ end
11
+
12
+ before do
13
+ Configurable.restore_default_configuration
14
+ end
15
+
16
+ it 'With default' do
17
+ Configurable.with_default.must_equal 'default value'
18
+ end
19
+
20
+ it 'Without default' do
21
+ Configurable.without_default.must_be_nil
22
+ end
23
+
24
+ it 'Get/Set' do
25
+ Configurable.setting.must_be_nil
26
+ Configurable.setting = :some_value
27
+ Configurable.setting.must_equal :some_value
28
+ end
29
+
30
+ it 'Restore defaults' do
31
+ Configurable.with_default = :value_1
32
+ Configurable.without_default = :value_2
33
+ Configurable.setting = :value_3
34
+
35
+ Configurable.restore_default_configuration
36
+
37
+ Configurable.with_default.must_equal 'default value'
38
+ Configurable.without_default.must_be_nil
39
+ Configurable.setting.must_be_nil
40
+ end
41
+
42
+ it 'Dump configuration' do
43
+ Configurable.setting = :dump
44
+
45
+ Configurable.configuration.must_equal with_default: 'default value',
46
+ without_default: nil,
47
+ setting: :dump
48
+ end
49
+
50
+ it 'Configure block' do
51
+ Configurable.configure do |config|
52
+ config.setting = :config_block
53
+ end
54
+
55
+ Configurable.setting.must_equal :config_block
56
+ end
57
+
58
+ end
@@ -0,0 +1,2 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
@@ -0,0 +1,9 @@
1
+ require 'coverage_helper'
2
+ require 'minitest/autorun'
3
+ require 'turn'
4
+ load File.expand_path('../../lib/class_config.rb', __FILE__)
5
+
6
+ Turn.config do |c|
7
+ c.format = :pretty
8
+ c.natural = true
9
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: class_config
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Naiman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-07 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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'
34
+ type: :development
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '4.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '4.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: turn
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Class configuration attributes
98
+ email:
99
+ - gabynaiman@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - class_config.gemspec
110
+ - lib/class_config.rb
111
+ - spec/class_config_spec.rb
112
+ - spec/coverage_helper.rb
113
+ - spec/minitest_helper.rb
114
+ homepage: https://github.com/gabynaiman/class_config
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.1.10
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Class configuration attributes
138
+ test_files:
139
+ - spec/class_config_spec.rb
140
+ - spec/coverage_helper.rb
141
+ - spec/minitest_helper.rb