Permalink
Browse files

removed Syck support for Ruby 2.0.0.

  • Loading branch information...
1 parent 34dbc2d commit d2a2d20628d72e1a41bc9efebb1b290f22c0cb92 @markbates committed Feb 8, 2013
Showing with 78 additions and 70 deletions.
  1. +1 −1 .travis.yml
  2. +59 −61 README.textile → README.md
  3. +11 −3 lib/configatron/store.rb
  4. +1 −1 lib/configatron/version.rb
  5. +6 −4 spec/lib/configatron_spec.rb
View
@@ -4,6 +4,6 @@ rvm:
- 1.9.3
- jruby-19mode
- rbx-19mode
- - ruby-head
+ - 2.0.0
script: bundle exec rspec
@@ -1,112 +1,110 @@
-h1. Configatron
+# Configatron [![Build Status](https://travis-ci.org/markbates/configatron.png?branch=master)](https://travis-ci.org/markbates/configatron)
Configatron makes configuring your applications and scripts incredibly easy. No longer is a there a need to use constants or global variables. Now you can use a simple and painless system to configure your life. And, because it's all Ruby, you can do any crazy thing you would like to!
-h2. Installation
+## Installation
Installation of Configatron is easy, as it is just a RubyGem:
-<pre><code>
+```ruby
$ sudo gem install configatron
-</code></pre>
+```
If you'd like to live on the bleedin' edge you can install the development version from GitHub:
-<pre><code>
+```
$ sudo gem install markbates-configatron --source=http://gems.github.com
-</code></pre>
+```
Once installed you just need to require it:
-<pre><code>
+```ruby
require 'configatron'
-</code></pre>
+```
-h2. Examples
+## Examples
-h3. Simple
+### Simple
-<pre><code>
+```ruby
configatron.email = 'me@example.com'
configatron.database_url = "postgres://localhost/mack_framework_rocks"
-</code></pre>
+```
Now, anywhere in your code you can do the following:
-<pre><code>
+```ruby
configatron.email # => "me@example.com"
configatron.database_url # => "postgres://localhost/mack_framework_rocks"
-</code></pre>
+```
Viola! Simple as can be.
Now you're saying, what if I want to have a 'default' set of options, but then override them later, based on other information? Simple again. Let's use our above example. We've configured our @database_url@ option to be @postgres://localhost/mack_framework_rocks@. The problem with that is that is our production database url, not our development url. Fair enough, all you have to do is redeclare it:
-<pre><code>
+```ruby
configatron.database_url = "postgres://localhost/mack_framework_rocks_development"
-</code></pre>
+```
becomes:
-<pre><code>
+```ruby
configatron.email # => "me@example.com"
configatron.database_url # => "postgres://localhost/mack_framework_rocks_development"
-</code></pre>
+```
Notice how our other configuration parameters haven't changed? Cool, eh?
-h3. Hash/YAML
+### Hash/YAML
You can configure configatron from a hash as well (this is really only useful in testing or for data driven configurat, it's not recommended for actual configuration):
-<pre><code>
- configatron.configure_from_hash({:email => {:pop => {:address => 'pop.example.com', :port => 110}}, :smtp => {:address => 'smtp.example.com'}})
-
+```ruby
+ configatron.configure_from_hash({:email => {:pop => {:address => 'pop.example.com', :port => 110}}, :smtp => {:address => 'smtp.example.com'}})####
configatron.email.pop.address # => 'pop.example.com'
configatron.email.pop.port # => 110
# and so on...
-</code></pre>
+```
-h4. YAML
+#### YAML
Support for YAML has been deprecated and will be removed in version 2.9 of Configatron. Please switch to Ruby based configuration of Configatron. Trust me, it's a lot nicer and easier to use. Why would you _not_ want to?
-h3. Namespaces
+### Namespaces
The question that should be on your lips is what I need to have namespaced configuration parameters. It's easy! Configatron allows you to create namespaces.
-<pre><code>
+```ruby
configatron.website_url = "http://www.mackframework.com"
configatron.email.pop.address = "pop.example.com"
configatron.email.pop.port = 110
configatron.email.smtp.address = "smtp.example.com"
configatron.email.smtp.port = 25
-</code></pre>
+```
becomes:
-<pre><code>
+```ruby
configatron.email.pop.address # => "pop.example.com"
configatron.email.smtp.address # => "smtp.example.com"
configatron.website_url # => "http://www.mackframework.com"
-</code></pre>
-
-Configatron allows you to nest namespaces to your hearts content! Just keep going, it's that easy.
+```
+####onfigatron allows you to nest namespaces to your hearts content! Just keep going, it's that easy.
Of course you can update a single parameter n levels deep as well:
-<pre><code>
+```ruby
configatron.email.pop.address = "pop2.example.com"
configatron.email.pop.address # => "pop2.example.com"
configatron.email.smtp.address # => "smtp.example.com"
-</code></pre>
+```
-h3. Temp Configurations
+### Temp Configurations
Sometimes in testing, or other situations, you want to temporarily change some settings. You can do this with the @temp@ method:
-<pre><code>
+```ruby
configatron.one = 1
configatron.letters.a = 'A'
configatron.letters.b = 'B'
@@ -122,16 +120,16 @@ Sometimes in testing, or other situations, you want to temporarily change some s
configatron.letters.a # => 'A'
configatron.letters.b # => 'B'
configatron.letters.c # => nil
-</code></pre>
+```
You can also pass in an optional Hash to the @temp@:
-<pre><code>
+```ruby
configatron.one = 1
configatron.letters.a = 'A'
configatron.letters.b = 'B'
configatron.temp(:letters => {:b => 'bb', :c => 'c'}) do
- configatron.one == 1
+ ####one == 1
configatron.letters.a # => 'A'
configatron.letters.b # => 'bb'
configatron.letters.c # => 'c'
@@ -140,13 +138,13 @@ You can also pass in an optional Hash to the @temp@:
configatron.letters.a # => 'A'
configatron.letters.b # => 'B'
configatron.letters.c # => nil
-</code></pre>
+```
-h3. Delayed and Dynamic Configurations
+### Delayed and Dynamic Configurations
There are times when you want to refer to one configuration setting in another configuration setting. Let's look at a fairly contrived example:
-<pre><code>
+```ruby
configatron.memcached.servers = ['127.0.0.1:11211']
configatron.page_caching.servers = configatron.memcached.servers
configatron.object_caching.servers = configatron.memcached.servers
@@ -160,15 +158,15 @@ There are times when you want to refer to one configuration setting in another c
configatron.page_caching.servers = configatron.memcached.servers
configatron.object_caching.servers = configatron.memcached.servers
end
-</code></pre>
+```
-Now, we could've written that slightly differently, but it helps to illustrate the point. With Configatron you can create <code>Delayed</code> and <code>Dynamic</code> settings.
+Now, we could've written that slightly differently, but it helps to illustrate the point. With Configatron you can create `Delayed` and `Dynamic` settings.
-h4. Delayed
+#### Delayed
-With <code>Delayed</code> settings execution of the setting doesn't happen until the first time it is executed.
+With `Delayed` settings execution of the setting doesn't happen until the first time it is executed.
-<pre><code>
+```ruby
configatron.memcached.servers = ['127.0.0.1:11211']
configatron.page_caching.servers = Configatron::Delayed.new {configatron.memcached.servers}
configatron.object_caching.servers = Configatron::Delayed.new {configatron.memcached.servers}
@@ -178,49 +176,49 @@ With <code>Delayed</code> settings execution of the setting doesn't happen until
elsif Rails.env == 'staging'
configatron.memcached.servers = ['192.168.0.2:11211']
end
-</code></pre>
+```
-Execution occurs once and after that the result of that execution is returned. So in our case the first time someone calls the setting <code>configatron.page_caching.servers</code> it will find the <code>configatron.memcached.servers</code> setting and return that. After that point if the <code>configatron.memcached.servers</code> setting is changed, the original settings are returned by <code>configatron.page_caching.servers</code>.
+Execution occurs once and after that the result of that execution is returned. So in our case the first time someone calls the setting `configatron.page_caching.servers` it will find the `configatron.memcached.servers` setting and return that. After that point if the `configatron.memcached.servers` setting is changed, the original settings are returned by `configatron.page_caching.servers`.
-h4. Dynamic
+#### Dynamic
-<code>Dynamic</code> settings are very similar to <code>Delayed</code> settings, but with one big difference. Every time you call a <code>Dynamic</code> setting is executed. Take this example:
+`Dynamic` settings are very similar to `Delayed` settings, but with one big difference. Every time you call a `Dynamic` setting is executed. Take this example:
-<pre><code>
+```ruby
configatron.current.time = Configatron::Dynamic.new {Time.now}
-</code></pre>
+```
-Each time you call <code>configatron.current.time</code> it will return a new value to you. While this seems a bit useless, it is pretty useful if you have ever changing configurations.
+Each time you call `configatron.current.time` it will return a new value to you. While this seems a bit useless, it is pretty useful if you have ever changing configurations.
-h3. Misc.
+### Misc.
Even if parameters haven't been set, you can still call them, but you'll get a @Configatron::Store@ object back. The Configatron::Store class, however, will respond true to @.nil?@ if there are no parameters configured on it.
-<pre><code>
+```ruby
configatron.i.dont.exist.nil? # => true
configatron.i.dont.exist # => Configatron::Store
-</code></pre>
+```
If you want to get back an actual @nil@ then you can use the @retrieve@ method:
-<pre><code>
+```ruby
configatron.i.do.exist = [:some, :array]
configatron.i.dont.retrieve(:exist, nil) # => nil
configatron.i.do.retrieve(:exist, :foo) # => [:some, :array]
-</code></pre>
+```
You can set 'default' values for parameters. If there is already a setting, it won't be replaced. This is useful if you've already done your 'configuration' and you call a library, that needs to have parameters set. The library can set its defaults, without worrying that it might have overridden your custom settings.
-<pre><code>
+```ruby
configatron.set_default(:name, 'Mark Bates')
configatron.name # => 'Mark Bates'
configatron.set_default(:name, 'Me')
configatron.name # => 'Mark Bates'
-</code></pre>
+```
Enjoy!
-h2. Contributors
+## Contributors
* Mark Bates
* Kurtis Rainbolt-Greene
View
@@ -299,11 +299,19 @@ def methods_include?(name)
self.methods.include?(RUBY_VERSION > '1.9.0' ? name.to_sym : name.to_s)
end
+ def is_syck?(obj)
+ if defined?(SYCK_CONSTANT)
+ Configatron.log.warn "DEPRECATED! (SYCK) Syck support has been removed from Configatron in Ruby 2.x. This feature will be removed entirely in Configatron 3.0. Please be advised."
+ obj.is_a?(SYCK_CONSTANT)
+ end
+ return false
+ end
+
def parse_options(options)
if options.is_a?(Hash)
options.each do |k,v|
if v.is_a?(Hash)
- if v.keys.length == 1 && v.keys.first.is_a?(SYCK_CONSTANT)
+ if v.keys.length == 1 && is_syck?(v.keys.first)
self.method_missing("#{k}=", v.values.first.flatten)
else
self.method_missing(k.to_sym).configure_from_hash(v)
@@ -324,8 +332,8 @@ def parse_options(options)
if RUBY_PLATFORM == 'java'
SYCK_CONSTANT = YAML::Yecht::MergeKey
- else
- SYCK_CONSTANT = (RUBY_VERSION.match(/^1\.9/) ? Syck::MergeKey : YAML::Syck::MergeKey)
+ elsif RUBY_VERSION.match(/^1\.9/)
+ SYCK_CONSTANT = Syck::MergeKey
end
end # Store
@@ -1,3 +1,3 @@
class Configatron
- VERSION = "2.9.2"
+ VERSION = "2.10.0"
end
@@ -351,10 +351,12 @@
end
it 'should handle merged keys' do
- configatron.food.should be_nil
- configatron.configure_from_yaml(File.join(File.dirname(__FILE__), 'merge.yml'))
- configatron.food.should_not be_nil
- configatron.food.list.should == [:apple, :banana, :tomato, :brocolli, :spinach]
+ unless RUBY_VERSION.match(/^2\.0/)
+ configatron.food.should be_nil
+ configatron.configure_from_yaml(File.join(File.dirname(__FILE__), 'merge.yml'))
+ configatron.food.should_not be_nil
+ configatron.food.list.should == [:apple, :banana, :tomato, :brocolli, :spinach]
+ end
end
it "should handle complex yaml" do

0 comments on commit d2a2d20

Please sign in to comment.