block_configurable 0.9.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0835eaa0da15465594873dedfc834e28ca02221c
4
+ data.tar.gz: 24fb1fc30a11579a5da38a7d98a73f23df2e9d7d
5
+ SHA512:
6
+ metadata.gz: bddd854d8a75024647a1bb7b4c37fd89956e10d2c787fcdc60393c44c72a99e7b9a655b9e7c41aa1f9bca791b004d63a49709a3c2f055e8a8d748ee37f8861f1
7
+ data.tar.gz: 21c0469b08b1323f2166f39b701ddbb49ea13d67af91d18131cdb93c5884ea4129a53ec6d816d9c9b7953a71d3b2eabef09f6320b864720ba289695a87b5b560
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-19mode
6
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in block_configurable.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Artem Shitov
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,49 @@
1
+ # BlockConfigurable
2
+
3
+ [![Build Status](https://travis-ci.org/artemshitov/block_configurable.png?branch=master)](https://travis-ci.org/artemshitov/block_configurable) [![Code Climate](https://codeclimate.com/github/artemshitov/block_configurable.png)](https://codeclimate.com/github/artemshitov/block_configurable)
4
+
5
+ A little mixin to make your classes and modules configurable using either single statements or blocks.
6
+
7
+ ## Installation
8
+
9
+ Install as a standalone gem:
10
+
11
+ gem install block_configurable
12
+
13
+ Or include into your `Gemfile`:
14
+
15
+ gem 'block_configurable', '~> 0.9.0'
16
+
17
+ ## Usage
18
+
19
+ ```ruby
20
+ class MyClass
21
+ include BlockConfigurable
22
+
23
+ config :param_with_default_value, 'A default!'
24
+ config :param_without_default_value
25
+ config :another_one
26
+ end
27
+
28
+ MyClass.configuration.param_with_default_value
29
+ #=> 'A default!'
30
+
31
+ MyClass.configuration.param_without_default_value
32
+ #=> nil
33
+
34
+ MyClass.configure do |c|
35
+ c.param_with_default_value = 'My values, my rules'
36
+ c.param_without_default_value = 'A value now!'
37
+ end
38
+
39
+ MyClass.configuration.param_with_default_value
40
+ #=> 'My values, my rules'
41
+
42
+ MyClass.configuration.param_without_default_value
43
+ #=> 'A value now!'
44
+
45
+ MyClass.configuration.another_one = 'The third'
46
+
47
+ MyClass.configuration.another_one
48
+ #=> 'The third'
49
+ ```
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/*_test.rb', 'test/**/*_test.rb']
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'block_configurable/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "block_configurable"
8
+ spec.version = BlockConfigurable::VERSION
9
+ spec.authors = ["Artem Shitov"]
10
+ spec.email = ["inbox@artemshitov.ru"]
11
+ spec.description = %q{A little mixin to make your classes and modules configurable using either single statements or blocks.}
12
+ spec.summary = %q{A little mixin to make your classes and modules configurable}
13
+ spec.homepage = "https://github.com/artemshitov/block_configurable"
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", '~> 5.0.6'
24
+ end
@@ -0,0 +1,23 @@
1
+ require 'block_configurable/configuration'
2
+ require "block_configurable/version"
3
+
4
+ module BlockConfigurable
5
+ module ClassMethods
6
+ def configuration
7
+ @configuration ||= Configuration.new
8
+ end
9
+
10
+ def config(param, default = nil)
11
+ configuration.add_config(param, default)
12
+ end
13
+
14
+ def configure(&block)
15
+ yield(configuration)
16
+ end
17
+ end
18
+
19
+ def self.included(receiver)
20
+ receiver.extend ClassMethods
21
+ receiver.send :private_class_method, :config
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ module BlockConfigurable
2
+ class Configuration
3
+ def add_config(param, default = nil)
4
+ instance_eval %Q{
5
+ def #{param}
6
+ @#{param}
7
+ end
8
+
9
+ def #{param}=(value)
10
+ @#{param} = value
11
+ end
12
+ }
13
+
14
+ instance_variable_set "@#{param}", default
15
+ end
16
+
17
+ def to_h
18
+ instance_variables.reduce(Hash.new) do |a, e|
19
+ a.merge(e[1..-1].to_sym => instance_variable_get(e))
20
+ end
21
+ end
22
+
23
+ alias_method :to_hash, :to_h
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module BlockConfigurable
2
+ VERSION = "0.9.0"
3
+ end
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+ require 'block_configurable'
3
+
4
+ class Configurable
5
+ include BlockConfigurable
6
+
7
+ config :value_with_default, 1
8
+ config :value_without_default, nil
9
+ config :value_to_change, 'a'
10
+ config :value_to_test_hash, :test
11
+ end
12
+
13
+ module ConfigurableModule
14
+ include BlockConfigurable
15
+
16
+ config :value_with_default, 1
17
+ end
18
+
19
+ class BlockConfigurableTest < Minitest::Test
20
+ attr_reader :configuration
21
+
22
+ def setup
23
+ @configuration = Configurable.configuration
24
+ end
25
+
26
+ def test_default_values
27
+ assert_equal 1, configuration.value_with_default
28
+ assert_nil configuration.value_without_default
29
+ end
30
+
31
+ def test_can_be_configured_with_block
32
+ assert_equal 'a', configuration.value_to_change
33
+
34
+ Configurable.configure do |c|
35
+ c.value_to_change = 'b'
36
+ end
37
+
38
+ assert_equal 'b', configuration.value_to_change
39
+ end
40
+
41
+ def test_can_be_converted_to_hash
42
+ assert_equal 4, configuration.to_hash.size
43
+ assert_equal :test, configuration.to_h[:value_to_test_hash]
44
+ end
45
+
46
+ def test_can_be_included_in_a_module_too
47
+ assert_equal 1, ConfigurableModule.configuration.value_with_default
48
+ end
49
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'minitest/autorun'
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: block_configurable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Artem Shitov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-31 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: 5.0.6
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 5.0.6
55
+ description: A little mixin to make your classes and modules configurable using either
56
+ single statements or blocks.
57
+ email:
58
+ - inbox@artemshitov.ru
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - .travis.yml
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - block_configurable.gemspec
70
+ - lib/block_configurable.rb
71
+ - lib/block_configurable/configuration.rb
72
+ - lib/block_configurable/version.rb
73
+ - test/block_configurable/block_configurable_test.rb
74
+ - test/test_helper.rb
75
+ homepage: https://github.com/artemshitov/block_configurable
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.0.0
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: A little mixin to make your classes and modules configurable
99
+ test_files:
100
+ - test/block_configurable/block_configurable_test.rb
101
+ - test/test_helper.rb