ruby-conf 1.1.0 → 1.3.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.
data/README.rdoc CHANGED
@@ -23,6 +23,9 @@
23
23
  number_legs 2
24
24
  name 'Nancy' , 'Drew'
25
25
  age 34
26
+
27
+ # make sure to pass a lambda and not a do block
28
+ # do blocks chain configurations (see below)
26
29
  number_of_bananas_eaten lambda {
27
30
  BanannaChomper.lookup("nancy.bananas").count
28
31
  }
@@ -32,6 +35,25 @@
32
35
  MyBonobo.number_legs # 2
33
36
  ...
34
37
 
38
+ === Anonymous configurations
39
+ config = RubyConf.define do
40
+ favorite_color 'blue'
41
+ end
42
+ config.favorite_color # "blue"
43
+
44
+ === Configuration chaining
45
+ RubyConf.define "rails", :as => :RailsConfig do
46
+ production do
47
+ database "rails_prod"
48
+ host "localhost"
49
+ end
50
+ staging do
51
+ database "rails_staging"
52
+ host "localhost"
53
+ end
54
+ end
55
+ RailsConfig.production.database # "rails_prod"
56
+ RailsConfig.staging.database # "rails_staging"
35
57
 
36
58
  == Contributing to ruby-conf
37
59
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.3.0
data/lib/ruby-conf.rb CHANGED
@@ -12,7 +12,9 @@ class RubyConf
12
12
  def method_missing(name, *args, &block)
13
13
  case(args.size)
14
14
  when 0:
15
- if @attributes.has_key? name.to_sym
15
+ if block_given?
16
+ @attributes[name.to_sym] = RubyConf.define(&block)
17
+ elsif @attributes.has_key? name.to_sym
16
18
  value = @attributes[name.to_sym]
17
19
 
18
20
  if value.is_a?(Proc)
@@ -54,11 +56,11 @@ class RubyConf
54
56
  #
55
57
  # @param [Symbol] namespace of the config
56
58
  # @param [Hash] list of options. e.g. :as => ConstantName
57
- def self.define(name, options = {}, &block)
59
+ def self.define(name = nil , options = {}, &block)
58
60
  config = Config.new
59
- @@configs[name.to_sym] = config
60
61
  config.instance_eval &block
61
62
 
63
+ @@configs[name.to_sym] = config unless name.nil?
62
64
  if options.has_key? :as
63
65
  Object.const_set(options[:as].to_s.to_sym, config)
64
66
  end
data/ruby-conf.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruby-conf}
8
- s.version = "1.1.0"
8
+ s.version = "1.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Curtis Schofield & Hollin Wilkins"]
@@ -16,6 +16,14 @@ describe RubyConf do
16
16
  subject { RubyConf }
17
17
 
18
18
  describe ".define" do
19
+ context "no arguments" do
20
+ it "returns anonymous config" do
21
+ config = subject.define do
22
+ equality true
23
+ end
24
+ config.equality.should be_true
25
+ end
26
+ end
19
27
  context ":as" do
20
28
  it "creates a global Constant" do
21
29
  subject.define "rails_database", :as => :RailsDatabase do
@@ -26,11 +34,12 @@ describe RubyConf do
26
34
  ::RailsDatabase.production[:password].should_not be_nil
27
35
  end
28
36
  end
29
- it "returns a config" do
30
- config = subject.define "config" do
37
+ it "returns a named config" do
38
+ config = subject.define "a_name" do
31
39
  something "hi"
32
40
  end
33
41
  config.something.should == "hi"
42
+ subject.a_name.something.should == 'hi'
34
43
  end
35
44
  it "can be chained" do
36
45
  subject.define "config", :as => :MyConfig do
@@ -40,6 +49,21 @@ describe RubyConf do
40
49
  end
41
50
  MyConfig.love_song.title.should == 'in me all along'
42
51
  end
52
+ it "can be chained using do blocks instead of RubyConf.define" do
53
+ subject.define "config", :as => :MyConfig do
54
+ turtles do
55
+ teenage true
56
+ mutant true
57
+ ninja true
58
+
59
+ raphael do
60
+ mask "red"
61
+ end
62
+ end
63
+ end
64
+ MyConfig.turtles.mutant.should == true
65
+ MyConfig.turtles.raphael.mask.should == "red"
66
+ end
43
67
  it "defines a new configuration with a given name" do
44
68
  subject.define "thing" do end
45
69
  subject.should respond_to(:thing)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-conf
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 1
8
+ - 3
9
9
  - 0
10
- version: 1.1.0
10
+ version: 1.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Curtis Schofield & Hollin Wilkins