konfigurator 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,8 +1,7 @@
1
1
  = Konfigurator
2
2
 
3
- Konfigurator is a configuration toolkit strongly inspired by Sinatra framework
4
- settings. Thanks to it you can easy implement configuration options to your apps,
5
- modules or classes. Take a look at simple example.
3
+ Konfigurator is a small and flexible configuration toolkit, which allow you
4
+ to configure your apps, classes or modules with DSL-style or Sinatra-like settings.
6
5
 
7
6
  == Installation
8
7
 
@@ -16,7 +15,7 @@ You can install Konfigurator simply using rubygems:
16
15
  cd konfigurator
17
16
  rake install
18
17
 
19
- == Basic usage
18
+ == Sinatra-like configuration
20
19
 
21
20
  Konfigurator is very easy to use. Take a look at simple example.
22
21
 
@@ -27,7 +26,7 @@ Konfigurator is very easy to use. Take a look at simple example.
27
26
  enable :bar
28
27
  disable :bla
29
28
 
30
- configure :production
29
+ configure :production do
31
30
  enable :bla
32
31
  set :spam, "eggs!"
33
32
  end
@@ -57,6 +56,44 @@ raised after try to get it direcly from class, eg:
57
56
  MyObject.exist # => true
58
57
  MyObject.not_exist # => will raise NoMethodError
59
58
 
59
+ == DSL-style configuration
60
+
61
+ Not there is also possible to use nice-looking DSL syntax provided by
62
+ <tt>Konfigurator::DSL</tt>. It allow you to configure your apps/classes
63
+ such like here:
64
+
65
+ Foo.configure do
66
+ host "127.0.0.1"
67
+ port 8080
68
+ password "secret"
69
+ end
70
+
71
+ But what's important in this kind of configuration, you have to define all possible
72
+ options first. You can define configuration attributes easy using <tt>#attr_config</tt>
73
+ (or <tt>#attr_setting</tt> alias).
74
+
75
+ class Foo
76
+ include Konfigurator::DSL
77
+
78
+ attr_config :host, :port
79
+ attr_config :password
80
+ end
81
+
82
+ Other use cases behave almost the same as with Konfigurator::Simple:
83
+
84
+ Foo.host # => "127.0.0.1"
85
+ Foo.port # => 8080
86
+
87
+ Foo.env :production
88
+ Foo.configure :production do
89
+ host "production.com"
90
+ port 80
91
+ end
92
+
93
+ foo = Foo.new
94
+ foo.settings.host # => "production.com"
95
+ foo.settings.port # => 80
96
+
60
97
  == Note on Patches/Pull Requests
61
98
 
62
99
  * Fork the project.
data/Rakefile CHANGED
@@ -5,11 +5,10 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "konfigurator"
8
- gem.summary = %Q{Configuration toolkit inspired by Sinatra settings.}
8
+ gem.summary = %Q{Small and flexible Configuration toolkit inspired i.a. by Sinatra settings.}
9
9
  gem.description = <<-DESCR
10
- Konfigurator is a configuration toolkit strongly ispired by Sinatra framework
11
- settings. Thanks to it you can easy implement configuration options to your apps,
12
- modules or classes.
10
+ Konfigurator is a small and flexible configuration toolkit, which allow you
11
+ to configure your apps, classes or modules with DSL-style or Sinatra-like settings.
13
12
  DESCR
14
13
  gem.email = "kriss.kowalik@gmail.com"
15
14
  gem.homepage = "http://github.com/nu7hatch/konfigurator"
@@ -47,7 +46,7 @@ require 'rake/rdoctask'
47
46
  Rake::RDocTask.new do |rdoc|
48
47
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
48
  rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "Trolley #{version}"
49
+ rdoc.title = "Konfigurator #{version}"
51
50
  rdoc.rdoc_files.include('README*')
52
51
  rdoc.rdoc_files.include('lib/**/*.rb')
53
52
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
@@ -0,0 +1,59 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{konfigurator}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kriss 'nu7hatch' Kowalik"]
12
+ s.date = %q{2010-10-07}
13
+ s.description = %q{ Konfigurator is a small and flexible configuration toolkit, which allow you
14
+ to configure your apps, classes or modules with DSL-style or Sinatra-like settings.
15
+ }
16
+ s.email = %q{kriss.kowalik@gmail.com}
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "konfigurator.gemspec",
28
+ "lib/konfigurator.rb",
29
+ "lib/konfigurator/dsl.rb",
30
+ "lib/konfigurator/simple.rb",
31
+ "test/helper.rb",
32
+ "test/test_dsl.rb",
33
+ "test/test_simple.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/nu7hatch/konfigurator}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{Small and flexible Configuration toolkit inspired i.a. by Sinatra settings.}
40
+ s.test_files = [
41
+ "test/test_dsl.rb",
42
+ "test/test_simple.rb",
43
+ "test/helper.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_development_dependency(%q<contest>, [">= 0.1.2"])
52
+ else
53
+ s.add_dependency(%q<contest>, [">= 0.1.2"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<contest>, [">= 0.1.2"])
57
+ end
58
+ end
59
+
data/lib/konfigurator.rb CHANGED
@@ -1,141 +1,63 @@
1
1
  require "yaml"
2
2
 
3
- # Konfigurator is a configuration toolkit strongly inspired by Sinatra framework
4
- # settings. Thanks to it you can easy implement configuration options to your apps,
5
- # modules or classes. Take a look at simple example.
6
- #
7
- # class MyClass do
8
- # set :foo, "bar"
9
- # enable :bar
10
- # disable :bla
11
- #
12
- # configure :production
13
- # enable :bla
14
- # set :spam, "eggs!"
15
- # end
16
- # end
17
- #
18
- # Now you can get configured options directly from your class:
19
- #
20
- # MyClass.foo # => "bar"
21
- # MyClass.bar # => true
22
- # MyClass.bla # => false
23
- #
24
- # ... or when current environment is set to <tt>:production</tt>:
25
- #
26
- # MyClass.bla # => true
27
- # MyClass.spam # => "eggs!"
28
- #
29
- # All settings are also available from objects via <tt>#settings</tt> method:
30
- #
31
- # obj = MyObject.new
32
- # obj.settings.foo # => "bar"
33
- # obk.settings.bar # => true
34
- #
35
- # <b>Remember!</b> when option is not set then <tt>NoMethodError</tt> will be
36
- # raised after try to get it direcly from class, eg:
37
- #
38
- # MyObject.set :exist
39
- # MyObject.exist # => true
40
- # MyObject.not_exist # => will raise NoMethodError
41
3
  module Konfigurator
4
+ # Available configuration types...
5
+ autoload :DSL, "konfigurator/dsl"
6
+ autoload :Simple, "konfigurator/simple"
42
7
 
43
8
  def self.included(base) # :nodoc:
44
- base.send(:extend, ClassMethods)
45
- base.send(:include, InstanceMethods)
9
+ # v0.0.1 compatibility...
10
+ base.send(:include, Konfigurator::Simple)
46
11
  end
47
-
48
- module InstanceMethods
49
- # Access to configuration options is defined in the class methods, so it's
50
- # only syntactic sugar for <tt>self.class</tt>.
51
- def settings
52
- self.class
53
- end
54
- alias :config :settings
55
- end # InstanceMethods
56
-
57
- module ClassMethods
58
- # Run once, at startup, in any environment. To add an option use the
59
- # <tt>set</tt> method (For boolean values You can use <tt>#enable</tt> and
60
- # <tt>#disable</tt> methods):
61
- #
62
- # configure do
63
- # set :foo, 'bar'
64
- # enable :bar
65
- # disable :yadayada
66
- # end
67
- #
68
- # Run only when the environment (or the <tt>APP_ENV</tt> env variable)is set
69
- # to <tt>:production</tt>:
70
- #
71
- # configure :production do
72
- # ...
73
- # end
74
- #
75
- # Run when the environment is set to either <tt>:production</tt> or <tt>:test</tt>:
76
- #
77
- # configure :production, :test do
78
- # ...
79
- # end
80
- def configure(*envs, &block)
81
- class_eval(&block) if envs.empty? || envs.include?(env.to_sym)
82
- end
83
-
84
- # It loads settings from given <tt>.yml</tt> file. File should have structure
85
- # like this one:
86
- #
87
- # development:
88
- # foo: bar
89
- # bar: true
90
- # production:
91
- # bla: foobar
92
- def load_settings(fname)
93
- conf = YAML.load_file(fname)
94
- conf[env.to_s].each {|k,v| set k.to_sym, v }
95
- end
96
12
 
97
- # Returns hash with defined configuration options.
98
- def settings
99
- @settings ||= {}
100
- end
101
- alias :config :settings
102
-
103
- # It "enables" given setting. It means that it assigns <tt>true</tt> value
104
- # to the specified setting key.
105
- #
106
- # enable :foo # => set :foo, true
107
- def enable(name)
108
- set(name, true)
109
- end
13
+ module Common
14
+ module InstanceMethods
15
+ # Access to configuration options is defined in the class methods, so it's
16
+ # only syntactic sugar for <tt>self.class</tt>.
17
+ def settings
18
+ self.class
19
+ end
20
+ alias :config :settings
21
+ end # InstanceMethods
110
22
 
111
- # It "disables" given setting. It means that it assigns <tt>false</tt> value
112
- # to the specified setting key.
113
- #
114
- # disable :foo # => set :foo, false
115
- def disable(name)
116
- set(name, false)
117
- end
118
-
119
- # Assigns given value to the specified setting key.
120
- #
121
- # set :foo, "YadaYadaYaday!"
122
- # set :bae, true
123
- #
124
- # See also shortcuts for boolean settings: <tt>#enable</tt> and
125
- # <tt>#disable</tt> methods.
126
- def set(name, value)
127
- name = name.to_sym
128
- unless self.respond_to?(name)
129
- meta = class << self; self; end
130
- meta.send(:define_method, name) { settings[name] }
131
- end
132
- settings[name] = value
133
- end
134
-
135
- # It returns name of current environment.
136
- def environment
137
- settings[:environment] ||= settings[:env] || ENV["APP_ENV"] || :development
138
- end
139
- alias :env :environment
140
- end # ClassMethods
23
+ module ClassMethods
24
+ # Run once, at startup, in any environment. To add an option use the
25
+ # <tt>set</tt> method (For boolean values You can use <tt>#enable</tt> and
26
+ # <tt>#disable</tt> methods):
27
+ #
28
+ # configure do
29
+ # set :foo, 'bar'
30
+ # enable :bar
31
+ # disable :yadayada
32
+ # end
33
+ #
34
+ # Run only when the environment (or the <tt>APP_ENV</tt> env variable)is set
35
+ # to <tt>:production</tt>:
36
+ #
37
+ # configure :production do
38
+ # ...
39
+ # end
40
+ #
41
+ # Run when the environment is set to either <tt>:production</tt> or <tt>:test</tt>:
42
+ #
43
+ # configure :production, :test do
44
+ # ...
45
+ # end
46
+ def configure(*envs, &block)
47
+ class_eval(&block) if envs.empty? || envs.include?(env.to_sym)
48
+ end
49
+
50
+ # Returns hash with defined configuration options.
51
+ def settings
52
+ @settings ||= {}
53
+ end
54
+ alias :config :settings
55
+
56
+ # It returns name of current environment.
57
+ def environment
58
+ settings[:environment] ||= settings[:env] || ENV["APP_ENV"] || :development
59
+ end
60
+ alias :env :environment
61
+ end # ClassMethods
62
+ end # Common
141
63
  end # Konfigurator
@@ -0,0 +1,74 @@
1
+ # This module provides configuration with nice-looking DSL syntax. It allow you
2
+ # to configure your apps/classes such like here:
3
+ #
4
+ # Foo.configure do
5
+ # host "127.0.0.1"
6
+ # port 8080
7
+ # password "secret"
8
+ # end
9
+ #
10
+ # But what's important in this kind of configuration, you have to define all possible
11
+ # options first. You can define configuration attributes easy using <tt>#attr_config</tt>
12
+ # (or <tt>#attr_setting</tt> alias).
13
+ #
14
+ # class Foo
15
+ # include Konfigurator::DSL
16
+ #
17
+ # attr_config :host, :port
18
+ # attr_config :password
19
+ # end
20
+ #
21
+ # Other use cases behave almost the same as with Konfigurator::Simple:
22
+ #
23
+ # Foo.host # => "127.0.0.1"
24
+ # Foo.port # => 8080
25
+ #
26
+ # Foo.env :production
27
+ # Foo.configure :production do
28
+ # host "production.com"
29
+ # port 80
30
+ # end
31
+ #
32
+ # foo = Foo.new
33
+ # foo.settings.host # => "production.com"
34
+ # foo.settings.port # => 80
35
+ module Konfigurator
36
+ module DSL
37
+ def self.included(base) # :nodoc:
38
+ base.send(:include, Common::InstanceMethods)
39
+ base.send(:extend, Common::ClassMethods)
40
+ base.send(:extend, ClassMethods)
41
+ end
42
+
43
+ module ClassMethods
44
+ # It defines given configuration attributes.
45
+ #
46
+ # attr_config :host, :port
47
+ # attr_config :password
48
+ def attr_config(*attrs)
49
+ attrs.each do |attr|
50
+ self.class.class_eval <<-EVAL
51
+ def #{attr.to_s}(value=nil)
52
+ settings[#{attr.to_sym.inspect}] = value unless value.nil?
53
+ return settings[#{attr.to_sym.inspect}]
54
+ end
55
+ EVAL
56
+ end
57
+ end
58
+ alias :attr_setting :attr_config
59
+
60
+ # See Konfigurator#environment for more info.
61
+ def environment(env=nil)
62
+ settings[:environment] = env unless env.nil?
63
+ settings[:environment] ||= settings[:env] || ENV["APP_ENV"] || :development
64
+ end
65
+ alias :env :environment
66
+
67
+ # See Konfigurator::Simple#load_settings for more info.
68
+ def load_settings(fname)
69
+ conf = YAML.load_file(fname)
70
+ conf[env.to_s].each {|k,v| send(k.to_sym, v) }
71
+ end
72
+ end # ClassMethods
73
+ end # DSL
74
+ end # Konfigurator
@@ -0,0 +1,94 @@
1
+ # Konfigurator::Simple is a configuration toolkit strongly inspired by Sinatra
2
+ # framework settings. Thanks to it you can easy implement configuration options
3
+ # to your apps, modules or classes. Take a look at simple example.
4
+ #
5
+ # class MyClass do
6
+ # set :foo, "bar"
7
+ # enable :bar
8
+ # disable :bla
9
+ #
10
+ # configure :production do
11
+ # enable :bla
12
+ # set :spam, "eggs!"
13
+ # end
14
+ # end
15
+ #
16
+ # Now you can get configured options directly from your class:
17
+ #
18
+ # MyClass.foo # => "bar"
19
+ # MyClass.bar # => true
20
+ # MyClass.bla # => false
21
+ #
22
+ # ... or when current environment is set to <tt>:production</tt>:
23
+ #
24
+ # MyClass.bla # => true
25
+ # MyClass.spam # => "eggs!"
26
+ #
27
+ # All settings are also available from objects via <tt>#settings</tt> method:
28
+ #
29
+ # obj = MyObject.new
30
+ # obj.settings.foo # => "bar"
31
+ # obk.settings.bar # => true
32
+ #
33
+ # <b>Remember!</b> when option is not set then <tt>NoMethodError</tt> will be
34
+ # raised after try to get it direcly from class, eg:
35
+ #
36
+ # MyObject.set :exist
37
+ # MyObject.exist # => true
38
+ # MyObject.not_exist # => will raise NoMethodError
39
+ module Konfigurator
40
+ module Simple
41
+ def self.included(base) # :nodoc:
42
+ base.send(:include, Common::InstanceMethods)
43
+ base.send(:extend, Common::ClassMethods)
44
+ base.send(:extend, ClassMethods)
45
+ end
46
+
47
+ module ClassMethods
48
+ # It "enables" given setting. It means that it assigns <tt>true</tt> value
49
+ # to the specified setting key.
50
+ #
51
+ # enable :foo # => set :foo, true
52
+ def enable(name)
53
+ set(name, true)
54
+ end
55
+
56
+ # It "disables" given setting. It means that it assigns <tt>false</tt> value
57
+ # to the specified setting key.
58
+ #
59
+ # disable :foo # => set :foo, false
60
+ def disable(name)
61
+ set(name, false)
62
+ end
63
+
64
+ # Assigns given value to the specified setting key.
65
+ #
66
+ # set :foo, "YadaYadaYaday!"
67
+ # set :bae, true
68
+ #
69
+ # See also shortcuts for boolean settings: <tt>#enable</tt> and
70
+ # <tt>#disable</tt> methods.
71
+ def set(name, value)
72
+ name = name.to_sym
73
+ unless self.respond_to?(name)
74
+ meta = class << self; self; end
75
+ meta.send(:define_method, name) { settings[name] }
76
+ end
77
+ settings[name] = value
78
+ end
79
+
80
+ # It loads settings from given <tt>.yml</tt> file. File should have structure
81
+ # like this one:
82
+ #
83
+ # development:
84
+ # foo: bar
85
+ # bar: true
86
+ # production:
87
+ # bla: foobar
88
+ def load_settings(fname)
89
+ conf = YAML.load_file(fname)
90
+ conf[env.to_s].each {|k,v| set k.to_sym, v }
91
+ end
92
+ end # ClassMethods
93
+ end # Simple
94
+ end # Konfigurator
data/test/helper.rb CHANGED
@@ -1,7 +1,49 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
 
4
+ require "rubygems"
4
5
  require "test/unit"
5
6
  require "contest"
7
+ require "fileutils"
6
8
  require "konfigurator"
7
9
 
10
+ COMMON_TESTS = <<-EVAL
11
+ should "respond to #environment and #env" do
12
+ assert subject.respond_to?(:environment)
13
+ assert subject.respond_to?(:env)
14
+ end
15
+
16
+ should "respond to #settings and #config" do
17
+ assert subject.respond_to?(:settings)
18
+ assert subject.respond_to?(:config)
19
+ end
20
+
21
+ should "respond to #configure" do
22
+ assert subject.respond_to?(:configure)
23
+ end
24
+ EVAL
25
+
26
+ CONFIG_FILE_CONTENT = <<-CONTENT
27
+ production:
28
+ foo: bar
29
+ bla: true
30
+ development:
31
+ foo: bla
32
+ bla: false
33
+ CONTENT
34
+
35
+ class ConfiguredWithSimple
36
+ include Konfigurator::Simple
37
+ end
38
+
39
+ class ConfiguredWithDSL
40
+ include Konfigurator::DSL
41
+ attr_config :foo, :bar
42
+ end
43
+
44
+ def with_conf_file(&block)
45
+ fname = File.join(File.dirname(__FILE__), 'conf.yml')
46
+ File.open(fname, "w+") {|f| f.write(CONFIG_FILE_CONTENT) }
47
+ yield fname
48
+ FileUtils.rm(fname)
49
+ end
data/test/test_dsl.rb ADDED
@@ -0,0 +1,53 @@
1
+ require "helper"
2
+
3
+ class TestDSL < Test::Unit::TestCase
4
+ describe "Object configured with Konfigurator::DSL" do
5
+ def subject
6
+ ConfiguredWithDSL
7
+ end
8
+
9
+ instance_eval COMMON_TESTS
10
+
11
+ should "respond to #attr_config and #attr_setting" do
12
+ assert subject.respond_to?(:attr_config)
13
+ assert subject.respond_to?(:attr_setting)
14
+ end
15
+
16
+ should "respond to defined #foo and #bar settings" do
17
+ assert subject.respond_to?(:foo)
18
+ assert subject.respond_to?(:bar)
19
+ end
20
+
21
+ should "allow to set config option value with DSL-style syntax" do
22
+ subject.foo :bar
23
+ assert_equal :bar, subject.foo
24
+ end
25
+
26
+ should "allow for quick access to current environment name" do
27
+ subject.environment :production
28
+ assert_equal :production, subject.environment
29
+ end
30
+
31
+ should "allow to load settings from yaml file" do
32
+ with_conf_file do |fname|
33
+ subject.environment :production
34
+ subject.attr_config :bla
35
+ subject.load_settings(fname)
36
+ assert subject.bla
37
+ assert_equal "bar", subject.foo
38
+ end
39
+ end
40
+
41
+ should "allow to define configuration specific for current env" do
42
+ subject.attr_config :prod, :dev, :bar
43
+ subject.environment :development
44
+ subject.prod false
45
+ subject.configure(:production) { prod true }
46
+ subject.configure(:development) { dev true }
47
+ subject.configure(:development, :production) { bar :foo }
48
+ assert subject.dev
49
+ assert !subject.prod
50
+ assert_equal :foo, subject.bar
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,84 @@
1
+ require "helper"
2
+
3
+ class TestSimple < Test::Unit::TestCase
4
+ describe "Konfigurator::Simple" do
5
+ def subject
6
+ ConfiguredWithSimple
7
+ end
8
+
9
+ instance_eval COMMON_TESTS
10
+
11
+ should "respond to #set" do
12
+ assert subject.respond_to?(:set)
13
+ end
14
+
15
+ should "respond to #enable" do
16
+ assert subject.respond_to?(:enable)
17
+ end
18
+
19
+ should "respond to #disable" do
20
+ assert subject.respond_to?(:disable)
21
+ end
22
+
23
+ should "allow to set given option" do
24
+ assert_equal "bar", subject.set(:foo, "bar")
25
+ assert_equal "bar", subject.settings[:foo]
26
+ end
27
+
28
+ should "allow to quick disable given option" do
29
+ assert !subject.disable(:foo)
30
+ assert !subject.foo
31
+ end
32
+
33
+ should "allow to quick enable given option" do
34
+ assert subject.enable(:foo)
35
+ assert subject.foo
36
+ end
37
+
38
+ should "allow for quick access to current environment name" do
39
+ subject.set :environment, :production
40
+ assert_equal :production, subject.environment
41
+ end
42
+
43
+ should "allow to define configuration specific for current env" do
44
+ subject.set :environment, :development
45
+ subject.disable :prod
46
+ subject.configure(:production) { enable :prod }
47
+ subject.configure(:development) { enable :dev }
48
+ subject.configure(:development, :production) { set :bar, :foo }
49
+ assert subject.dev
50
+ assert !subject.prod
51
+ assert_equal :foo, subject.bar
52
+ end
53
+
54
+ should "allow to load settings from yaml file" do
55
+ with_conf_file do |fname|
56
+ subject.set :environment, :production
57
+ subject.load_settings(fname)
58
+ assert subject.bla
59
+ assert_equal "bar", subject.foo
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "Object configured with Konfigurator::Simple" do
65
+ def subject
66
+ ConfiguredWithSimple
67
+ end
68
+
69
+ setup do
70
+ @configured = subject.new
71
+ end
72
+
73
+ should "respond to #settings and #config" do
74
+ assert @configured.respond_to?(:settings)
75
+ assert @configured.respond_to?(:config)
76
+ end
77
+
78
+ should "#settings works properly" do
79
+ subject.set(:fooo, :bar)
80
+ @configured = subject.new
81
+ assert_equal :bar, @configured.settings.fooo
82
+ end
83
+ end
84
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: konfigurator
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kriss 'nu7hatch' Kowalik
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-22 00:00:00 +02:00
18
+ date: 2010-10-07 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -34,7 +34,7 @@ dependencies:
34
34
  version: 0.1.2
35
35
  type: :development
36
36
  version_requirements: *id001
37
- description: " Konfigurator is a configuration toolkit strongly ispired by Sinatra framework\n settings. Thanks to it you can easy implement configuration options to your apps, \n modules or classes. \n"
37
+ description: " Konfigurator is a small and flexible configuration toolkit, which allow you \n to configure your apps, classes or modules with DSL-style or Sinatra-like settings.\n"
38
38
  email: kriss.kowalik@gmail.com
39
39
  executables: []
40
40
 
@@ -49,10 +49,13 @@ files:
49
49
  - README.rdoc
50
50
  - Rakefile
51
51
  - VERSION
52
+ - konfigurator.gemspec
52
53
  - lib/konfigurator.rb
53
- - test/conf.yml
54
+ - lib/konfigurator/dsl.rb
55
+ - lib/konfigurator/simple.rb
54
56
  - test/helper.rb
55
- - test/test_konfigurator.rb
57
+ - test/test_dsl.rb
58
+ - test/test_simple.rb
56
59
  has_rdoc: true
57
60
  homepage: http://github.com/nu7hatch/konfigurator
58
61
  licenses: []
@@ -86,7 +89,8 @@ rubyforge_project:
86
89
  rubygems_version: 1.3.7
87
90
  signing_key:
88
91
  specification_version: 3
89
- summary: Configuration toolkit inspired by Sinatra settings.
92
+ summary: Small and flexible Configuration toolkit inspired i.a. by Sinatra settings.
90
93
  test_files:
91
- - test/test_konfigurator.rb
94
+ - test/test_dsl.rb
95
+ - test/test_simple.rb
92
96
  - test/helper.rb
data/test/conf.yml DELETED
@@ -1,6 +0,0 @@
1
- production:
2
- foo: bar
3
- bla: true
4
- development:
5
- foo: bla
6
- bla: false
@@ -1,96 +0,0 @@
1
- require "helper"
2
-
3
- class Configured
4
- include Konfigurator
5
- end
6
-
7
- class TestKonfigurator < Test::Unit::TestCase
8
- describe "Configured class" do
9
- should "respond to #set" do
10
- assert Configured.respond_to?(:set)
11
- end
12
-
13
- should "respond to #enable" do
14
- assert Configured.respond_to?(:enable)
15
- end
16
-
17
- should "respond to #disable" do
18
- assert Configured.respond_to?(:disable)
19
- end
20
-
21
- should "respond to #environment and #env" do
22
- assert Configured.respond_to?(:environment)
23
- assert Configured.respond_to?(:env)
24
- end
25
-
26
- should "respond to #settings and #config" do
27
- assert Configured.respond_to?(:settings)
28
- assert Configured.respond_to?(:config)
29
- end
30
-
31
- should "respond to #configure" do
32
- assert Configured.respond_to?(:configure)
33
- end
34
-
35
- should "allow to set given option" do
36
- assert_equal "bar", Configured.set(:foo, "bar")
37
- assert_equal "bar", Configured.settings[:foo]
38
- end
39
-
40
- should "allow to quick disable given option" do
41
- assert !Configured.disable(:foo)
42
- assert !Configured.foo
43
- end
44
-
45
- should "allow to quick enable given option" do
46
- assert Configured.enable(:foo)
47
- assert Configured.foo
48
- end
49
-
50
- should "allow for quick access to current environment name" do
51
- Configured.set :environment, :production
52
- assert_equal :production, Configured.environment
53
- end
54
-
55
- should "allow to define configuration specific for current env" do
56
- Configured.set :environment, :development
57
- Configured.disable :prod
58
- Configured.configure :production do
59
- enable :prod
60
- end
61
- Configured.configure :development do
62
- enable :dev
63
- end
64
- Configured.configure :development, :production do
65
- set :bar, :foo
66
- end
67
- assert Configured.dev
68
- assert !Configured.prod
69
- assert_equal :foo, Configured.bar
70
- end
71
-
72
- should "allow to load settings from yaml file" do
73
- Configured.set :environment, :production
74
- Configured.load_settings(File.dirname(__FILE__)+"/conf.yml")
75
- assert Configured.bla
76
- assert_equal "bar", Configured.foo
77
- end
78
- end
79
-
80
- describe "Configured object" do
81
- setup do
82
- @configured = Configured.new
83
- end
84
-
85
- should "respond to #settings and #config" do
86
- assert @configured.respond_to?(:settings)
87
- assert @configured.respond_to?(:config)
88
- end
89
-
90
- should "#settings works properly" do
91
- Configured.set(:fooo, :bar)
92
- @configured = Configured.new
93
- assert_equal :bar, @configured.settings.fooo
94
- end
95
- end
96
- end