cunfug 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +10 -0
- data/README.md +30 -0
- data/Rakefile +12 -0
- data/cunfug.gemspec +21 -0
- data/lib/cunfug/configuration.rb +29 -0
- data/lib/cunfug/version.rb +3 -0
- data/lib/cunfug.rb +5 -0
- data/test/configuration_test.rb +36 -0
- metadata +65 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Cunfug
|
2
|
+
|
3
|
+
A very small, lightweight and efficient configuration DSL for Ruby modules and classes.
|
4
|
+
|
5
|
+
## Prerequisites
|
6
|
+
|
7
|
+
Cunfug has been tested and confirmed as working on Ruby 1.9.2, Ruby 1.8.7, JRuby 1.6.0.rc1 and Rubinius 1.2.1.dev.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
If you're using Bundler, you should add Cunfug to your `Gemfile`:
|
12
|
+
gem "cunfug"
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
module MyApplication
|
17
|
+
include Cunfug::Configuration
|
18
|
+
end
|
19
|
+
|
20
|
+
MyApplication.configure do |config|
|
21
|
+
config.test_value = :test
|
22
|
+
config.foo = [ :a, :b ]
|
23
|
+
end
|
24
|
+
|
25
|
+
MyApplication.test_value # => :test
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Running the tests is possible via `rake spec` or just `rake`.
|
30
|
+
You're invited to send a pull request :)
|
data/Rakefile
ADDED
data/cunfug.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "cunfug/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "cunfug"
|
7
|
+
s.version = Cunfug::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Robert Glaser"]
|
10
|
+
s.email = ["mail@robert-glaser.de"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{A very small, lightweight and efficient configuration DSL for Ruby modules and classes.}
|
13
|
+
s.description = %q{A very small, lightweight and efficient configuration DSL for Ruby modules and classes.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "cunfug"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Cunfug
|
2
|
+
module Configuration
|
3
|
+
require 'active_support'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
#
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def method_missing(method_name, *args)
|
14
|
+
@config ||= OpenStruct.new
|
15
|
+
|
16
|
+
if method_name.to_s.match(/^.+=$/)
|
17
|
+
@config.send(method_name, args.first)
|
18
|
+
else
|
19
|
+
@config.send(method_name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def configure
|
24
|
+
yield self
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/cunfug.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'cunfug'
|
3
|
+
|
4
|
+
describe Cunfug::Configuration do
|
5
|
+
before do
|
6
|
+
module Foo
|
7
|
+
include Cunfug::Configuration
|
8
|
+
|
9
|
+
mattr_accessor :already_defined
|
10
|
+
|
11
|
+
self.already_defined = "already defined"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "when given a new config option" do
|
16
|
+
it "must return the freshly set value" do
|
17
|
+
Foo.test = :blub
|
18
|
+
Foo.test.must_equal :blub
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "when called with an unset option" do
|
23
|
+
it "must return nil" do
|
24
|
+
Foo.unset.must_equal nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "when given an already existing method name" do
|
29
|
+
it "should behave and do nothing" do
|
30
|
+
Foo.already_defined.must_equal "already defined"
|
31
|
+
Foo.already_defined = "bla"
|
32
|
+
Foo.already_defined.must_equal "bla"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cunfug
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Robert Glaser
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-02-15 00:00:00 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: A very small, lightweight and efficient configuration DSL for Ruby modules and classes.
|
18
|
+
email:
|
19
|
+
- mail@robert-glaser.de
|
20
|
+
executables: []
|
21
|
+
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
26
|
+
files:
|
27
|
+
- .gitignore
|
28
|
+
- Gemfile
|
29
|
+
- README.md
|
30
|
+
- Rakefile
|
31
|
+
- cunfug.gemspec
|
32
|
+
- lib/cunfug.rb
|
33
|
+
- lib/cunfug/configuration.rb
|
34
|
+
- lib/cunfug/version.rb
|
35
|
+
- test/configuration_test.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: ""
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project: cunfug
|
60
|
+
rubygems_version: 1.5.2
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: A very small, lightweight and efficient configuration DSL for Ruby modules and classes.
|
64
|
+
test_files:
|
65
|
+
- test/configuration_test.rb
|