class_options 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.rspec +3 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +119 -0
- data/Guardfile +15 -0
- data/LICENSE +24 -0
- data/README.md +30 -0
- data/class_options.gemspec +21 -0
- data/lib/class_options.rb +5 -0
- data/lib/class_options/options.rb +24 -0
- data/lib/class_options/version.rb +3 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/class_options/options/options_spec.rb +43 -0
- metadata +80 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
class_options (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
abstract_type (0.0.2)
|
10
|
+
adamantium (0.0.4)
|
11
|
+
backports (~> 2.6.4)
|
12
|
+
ice_nine (~> 0.6.0)
|
13
|
+
backports (2.6.5)
|
14
|
+
coderay (1.0.8)
|
15
|
+
descendants_tracker (0.0.1)
|
16
|
+
devutils (0.0.1)
|
17
|
+
rspec
|
18
|
+
thor
|
19
|
+
devutils-docs (0.0.1)
|
20
|
+
yard
|
21
|
+
devutils-guard (0.0.1)
|
22
|
+
guard
|
23
|
+
guard-bundler
|
24
|
+
guard-rspec
|
25
|
+
devutils-metrics (0.0.1)
|
26
|
+
flay
|
27
|
+
flog
|
28
|
+
mutant
|
29
|
+
pelusa
|
30
|
+
reek
|
31
|
+
roodi
|
32
|
+
simplecov
|
33
|
+
diff-lcs (1.1.3)
|
34
|
+
equalizer (0.0.1)
|
35
|
+
adamantium (~> 0.0.3)
|
36
|
+
backports (~> 2.6.4)
|
37
|
+
flay (1.4.3)
|
38
|
+
ruby_parser (~> 2.0)
|
39
|
+
sexp_processor (~> 3.0)
|
40
|
+
flog (2.5.3)
|
41
|
+
ruby_parser (~> 2.0)
|
42
|
+
sexp_processor (~> 3.0)
|
43
|
+
guard (1.6.0)
|
44
|
+
listen (>= 0.6.0)
|
45
|
+
lumberjack (>= 1.0.2)
|
46
|
+
pry (>= 0.9.10)
|
47
|
+
thor (>= 0.14.6)
|
48
|
+
guard-bundler (1.0.0)
|
49
|
+
bundler (~> 1.0)
|
50
|
+
guard (~> 1.1)
|
51
|
+
guard-rspec (2.3.3)
|
52
|
+
guard (>= 1.1)
|
53
|
+
rspec (~> 2.11)
|
54
|
+
ice_nine (0.6.0)
|
55
|
+
listen (0.6.0)
|
56
|
+
lumberjack (1.0.2)
|
57
|
+
mbj-inflector (0.0.1)
|
58
|
+
backports (~> 2.6.4)
|
59
|
+
method_source (0.8.1)
|
60
|
+
multi_json (1.5.0)
|
61
|
+
mutant (0.2.12)
|
62
|
+
abstract_type (~> 0.0.2)
|
63
|
+
adamantium (~> 0.0.4)
|
64
|
+
backports (~> 2.6)
|
65
|
+
descendants_tracker (~> 0.0.1)
|
66
|
+
diff-lcs (~> 1.1.3)
|
67
|
+
equalizer (~> 0.0.1)
|
68
|
+
ice_nine (~> 0.6.0)
|
69
|
+
mbj-inflector (~> 0.0.1)
|
70
|
+
to_source (~> 0.2.8)
|
71
|
+
mutant-melbourne (2.0.3)
|
72
|
+
pelusa (0.2.2)
|
73
|
+
pry (0.9.10)
|
74
|
+
coderay (~> 1.0.5)
|
75
|
+
method_source (~> 0.8)
|
76
|
+
slop (~> 3.3.1)
|
77
|
+
reek (1.2.13)
|
78
|
+
ripper_ruby_parser (~> 0.0.7)
|
79
|
+
ruby2ruby (~> 1.2.5)
|
80
|
+
ruby_parser (~> 2.0)
|
81
|
+
sexp_processor (~> 3.0)
|
82
|
+
ripper_ruby_parser (0.0.8)
|
83
|
+
sexp_processor (~> 3.0)
|
84
|
+
roodi (2.1.0)
|
85
|
+
ruby_parser
|
86
|
+
rspec (2.12.0)
|
87
|
+
rspec-core (~> 2.12.0)
|
88
|
+
rspec-expectations (~> 2.12.0)
|
89
|
+
rspec-mocks (~> 2.12.0)
|
90
|
+
rspec-core (2.12.2)
|
91
|
+
rspec-expectations (2.12.1)
|
92
|
+
diff-lcs (~> 1.1.3)
|
93
|
+
rspec-mocks (2.12.1)
|
94
|
+
ruby2ruby (1.2.5)
|
95
|
+
ruby_parser (~> 2.0)
|
96
|
+
sexp_processor (~> 3.0)
|
97
|
+
ruby_parser (2.3.1)
|
98
|
+
sexp_processor (~> 3.0)
|
99
|
+
sexp_processor (3.2.0)
|
100
|
+
simplecov (0.7.1)
|
101
|
+
multi_json (~> 1.0)
|
102
|
+
simplecov-html (~> 0.7.1)
|
103
|
+
simplecov-html (0.7.1)
|
104
|
+
slop (3.3.3)
|
105
|
+
thor (0.16.0)
|
106
|
+
to_source (0.2.9)
|
107
|
+
adamantium (~> 0.0.3)
|
108
|
+
mutant-melbourne (~> 2.0.3)
|
109
|
+
yard (0.8.3)
|
110
|
+
|
111
|
+
PLATFORMS
|
112
|
+
ruby
|
113
|
+
|
114
|
+
DEPENDENCIES
|
115
|
+
class_options!
|
116
|
+
devutils
|
117
|
+
devutils-docs
|
118
|
+
devutils-guard
|
119
|
+
devutils-metrics
|
data/Guardfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'bundler' do
|
5
|
+
watch('Gemfile')
|
6
|
+
# Uncomment next line if Gemfile contain `gemspec' command
|
7
|
+
watch(/^.+\.gemspec/)
|
8
|
+
end
|
9
|
+
|
10
|
+
guard 'rspec' do
|
11
|
+
watch(%r{^spec/.+_spec\.rb$})
|
12
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
13
|
+
watch('spec/spec_helper.rb') { "spec" }
|
14
|
+
end
|
15
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Copyright (c) 2012, Stefan Radomski & Rebecca Dietrich
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
* Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
* Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
* Neither the name of the libzero nor the
|
12
|
+
names of its contributors may be used to endorse or promote products
|
13
|
+
derived from this software without specific prior written permission.
|
14
|
+
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
16
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
17
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
DISCLAIMED. IN NO EVENT SHALL Stefan Radomski or Rebecca Dietrich BE LIABLE FOR ANY
|
19
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
20
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
21
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
22
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
24
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
ClassOptions
|
2
|
+
============
|
3
|
+
|
4
|
+
This is a small library to define class variables. These can then be used for
|
5
|
+
settings or information transportation.
|
6
|
+
|
7
|
+
Example
|
8
|
+
-------
|
9
|
+
|
10
|
+
# a default controller for web projects
|
11
|
+
class Controller
|
12
|
+
extend ClassOptions::Options
|
13
|
+
|
14
|
+
# the default request object to use
|
15
|
+
option :request_class
|
16
|
+
|
17
|
+
# we get a rack environment and create a new request object out of it
|
18
|
+
def initialize(env)
|
19
|
+
@request = self.class.request_class.new(env)
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_reader :request
|
23
|
+
end
|
24
|
+
|
25
|
+
# now you can define the default before using the class
|
26
|
+
Controller.request_class = Rack::Request
|
27
|
+
Controller.request_class = Zero::Request
|
28
|
+
|
29
|
+
Controller.new([]).request # => a Zero::Request
|
30
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/class_options/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'class_options'
|
6
|
+
s.version = ClassOptions::VERSION.dup
|
7
|
+
|
8
|
+
s.authors = ['Gibheer']
|
9
|
+
s.email = 'gibheer@gmail.com'
|
10
|
+
s.license = '3-clause BSD'
|
11
|
+
s.summary = 'define options on classes'
|
12
|
+
s.description = s.summary
|
13
|
+
s.homepage = 'http://github.com/gibheer/class_options'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.require_paths = %w(lib)
|
18
|
+
s.extra_rdoc_files = %w(README.md LICENSE)
|
19
|
+
|
20
|
+
s.rubygems_version = '1.8.24'
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ClassOptions
|
2
|
+
module Options
|
3
|
+
def options(*names)
|
4
|
+
names.each do |option|
|
5
|
+
create_option(option)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def create_option(option)
|
12
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
13
|
+
def self.#{option}=(value = ClassOptions::Undefined)
|
14
|
+
@#{option} = value
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.#{option}
|
19
|
+
@#{option} ||= ClassOptions::Undefined
|
20
|
+
end
|
21
|
+
RUBY
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'class_options'
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ClassOptions::Options, '#options' do
|
4
|
+
subject { testclass }
|
5
|
+
let (:function) { 'bar' }
|
6
|
+
let (:value) { 23 }
|
7
|
+
|
8
|
+
shared_examples_for 'an option' do
|
9
|
+
it { should respond_to(function) } # check getter
|
10
|
+
it { should respond_to(function + '=') } # check setter
|
11
|
+
|
12
|
+
it 'saves the option' do
|
13
|
+
subject.send(function + '=', value)
|
14
|
+
expect(subject.send(function)).to be(value)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'sets the default to Undefined' do
|
18
|
+
expect(subject.send(function)).to be(ClassOptions::Undefined)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with a single option' do
|
23
|
+
let(:testclass) do
|
24
|
+
Class.new do
|
25
|
+
extend ClassOptions::Options
|
26
|
+
options :bar
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it_behaves_like 'an option'
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'with many options' do
|
34
|
+
let(:testclass) do
|
35
|
+
Class.new do
|
36
|
+
extend ClassOptions::Options
|
37
|
+
options :foo, :bar
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it_behaves_like 'an option'
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: class_options
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gibheer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-08 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: define options on classes
|
15
|
+
email: gibheer@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files:
|
19
|
+
- README.md
|
20
|
+
- LICENSE
|
21
|
+
files:
|
22
|
+
- !binary |-
|
23
|
+
LmdpdGlnbm9yZQ==
|
24
|
+
- !binary |-
|
25
|
+
LnJzcGVj
|
26
|
+
- !binary |-
|
27
|
+
R2VtZmlsZQ==
|
28
|
+
- !binary |-
|
29
|
+
R2VtZmlsZS5sb2Nr
|
30
|
+
- !binary |-
|
31
|
+
R3VhcmRmaWxl
|
32
|
+
- !binary |-
|
33
|
+
TElDRU5TRQ==
|
34
|
+
- !binary |-
|
35
|
+
UkVBRE1FLm1k
|
36
|
+
- !binary |-
|
37
|
+
Y2xhc3Nfb3B0aW9ucy5nZW1zcGVj
|
38
|
+
- !binary |-
|
39
|
+
bGliL2NsYXNzX29wdGlvbnMucmI=
|
40
|
+
- !binary |-
|
41
|
+
bGliL2NsYXNzX29wdGlvbnMvb3B0aW9ucy5yYg==
|
42
|
+
- !binary |-
|
43
|
+
bGliL2NsYXNzX29wdGlvbnMvdmVyc2lvbi5yYg==
|
44
|
+
- !binary |-
|
45
|
+
c3BlYy9zcGVjX2hlbHBlci5yYg==
|
46
|
+
- !binary |-
|
47
|
+
c3BlYy91bml0L2NsYXNzX29wdGlvbnMvb3B0aW9ucy9vcHRpb25zX3NwZWMu
|
48
|
+
cmI=
|
49
|
+
homepage: http://github.com/gibheer/class_options
|
50
|
+
licenses:
|
51
|
+
- 3-clause BSD
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
none: false
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
none: false
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.8.24
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: define options on classes
|
74
|
+
test_files:
|
75
|
+
- !binary |-
|
76
|
+
c3BlYy9zcGVjX2hlbHBlci5yYg==
|
77
|
+
- !binary |-
|
78
|
+
c3BlYy91bml0L2NsYXNzX29wdGlvbnMvb3B0aW9ucy9vcHRpb25zX3NwZWMu
|
79
|
+
cmI=
|
80
|
+
has_rdoc:
|