RubyGems.org

Synopsys

Class-level configuration DSL

Installation

gem install config_accessor

Examples

require 'config_accessor'

class Remote
  configurable!

  config_accessor :host, :default => "localhost"
  config_accessor :port, :default => "80", :transform => :to_i
  config_accessor :proxy_host, :proxy_port
end

class Local < Remote
  config_accessor :l_port
end

Remote.host        # => "localhost"
Remote.port        # => 80
Remote.proxy_host  # => nil

r = Remote.new

r.port = "81"
r.port             # => 81
Remote.port        # => 80
Remote.port = 82

# next expressions are equivalent
r.port             # => 81
r.config[:port]    # => 81
r.config["port"]   # => 81
r.config.port      # => 81

# It supports inheritance, subclasses cannot change superclasses configurations
Local.port         # => 80

# You can do it with +configure+ method
Local.configure do
  port 81
end

# or
Local.configure do |config|
  config.port 81
end
installgem install config_accessor
Authors

Alexei Mikhailov

2,535 total downloads 1,314 for this version
Owners

F2a0c1d1afa1e9d83753ac26afc60470

Gemfile
gem 'config_accessor', '~> 0.0.3'
Versions
  1. 0.0.3 December 9, 2011 (7.5 KB)
  2. 0.0.2 December 9, 2011 (7 KB)
Show all versions (3 total)
Development Dependencies
  1. rspec >= 0