Permalink
Browse files

Change Setting to Settings

  • Loading branch information...
1 parent 8007ac0 commit aee3f7046a2775ea977ce76cf682801bb7914800 @binarylogic committed Oct 31, 2008
Showing with 54 additions and 71 deletions.
  1. +3 −0 CHANGELOG.rdoc
  2. +21 −25 README.rdoc
  3. +10 −1 lib/settingasm.rb
  4. +2 −15 lib/settingasm/config.rb
  5. +5 −5 lib/settingasm/{setting.rb → settings.rb}
  6. +4 −15 test/test_config.rb
  7. +1 −2 test/test_helper.rb
  8. +8 −8 test/test_setting.rb
View
@@ -0,0 +1,3 @@
+== 0.9.0 released 2008-10-30
+
+* Initial release
View
@@ -4,21 +4,7 @@ Settingasm is my personal solution to application wide settings that uses an ERB
So here is my question to you.....is Settingasm a great settings solution or the greatest?
-== 1. Configure
-
-Configuration is optional. See Settingasm::Config for more details.
-
- # config/initializers/settingasm.rb
- Settingasm::Config.configure do |config|
- config.file_name = :config # will look for config/config.yml
- config.file_name = "config" # will look for config
- config.file_name = "config.yaml" # will look for confg.yaml
- config.file_name = "/absolute/path/config.yml" # will look for /absolute/path/config.yaml
-
- config.class_name = "Setting" # use Setting.my_setting instead of Settingasm::Setting.my_setting
- end
-
-== 2. Create your settings
+== Create your settings
This is typical YAML file, notice ERB is allowed.
@@ -41,29 +27,39 @@ This is typical YAML file, notice ERB is allowed.
== Access your settings
-I use Setting because I specified it in my configuration. Otherwise you would have to use Settingasm::Setting. Since Setting is such a generic name I let you specify your own in the configuration. You could use anything you want.
-
>> RAILS_ENV
=> "development"
- >> Setting.cool
+ >> Settings.cool
=> "this is cool"
- >> Setting.cool.saweet
+ >> Settings.cool.saweet
=> "nested settings"
- >> Setting.new_setting
+ >> Settings.new_setting
=> 800
- >> Setting.awesome_setting
+ >> Settings.awesome_setting
=> "Did you know 5 + 5 = 10?"
== Multiple settings
- settings1 = Setting.new(:settings1) # looks for config/settings1.yml
- settings2 = Setting.new("setting2.yaml") # looks for config/settings2.yml
- settings3 = Setting.new(:some_setting => "some value")
-
+ settings1 = Settings.new(:settings1) # looks for config/settings1.yml
+ settings2 = Settings.new("setting2.yaml") # looks for config/settings2.yml
+ settings3 = Settings.new(:some_setting => "some value")
+
+== Configure
+
+Configuration is optional. See Settingasm::Config for more details.
+
+ # config/initializers/settingasm.rb
+ Settingasm::Config.configure do |config|
+ config.file_name = :config # will look for config/config.yml
+ config.file_name = "config" # will look for config
+ config.file_name = "config.yaml" # will look for confg.yaml
+ config.file_name = "/absolute/path/config.yml" # will look for /absolute/path/config.yaml
+ end
+
== Helpful links
* <b>Documentation:</b> http://settingasm.rubyforge.org
View
@@ -1,4 +1,13 @@
require "yaml"
require "erb"
require File.dirname(__FILE__) + "/settingasm/config"
-require File.dirname(__FILE__) + "/settingasm/setting"
+require File.dirname(__FILE__) + "/settingasm/settings"
+
+# Try to load conflicting Settings classes
+begin
+ Settings
+rescue(NameError)
+end
+
+# Since we don't have a Settings constant, lets go ahead and use it
+::Settings = Settingasm::Settings unless defined?(Settings)
@@ -6,24 +6,11 @@ class << self
def configure
yield self
end
-
- # The name of the class you want to use to access your settings. Maybe you don't like "Setting" or maybe it will conflict with a model you have. Just set this to "AppSetting" or "Config", whatever you want.
- #
- # * <tt>Default:</tt> "Setting"
- # * <tt>Accepts:</tt> Symbol or String
- def class_name
- @class_name
- end
- def class_name=(value) # :nodoc:
- eval("::#{value} = Setting")
- @class_name = value
- end
-
# The name of the file that your settings will be stored for singleton access. Meaning the settings file that will be used when calling methods on the class level:
#
- # Setting.setting1
- # Setting.setting2
+ # Settings.setting1
+ # Settings.setting2
# # etc...
#
# All that you need to do is specify the name of the file. It will automatically look in the config directory.
@@ -2,7 +2,7 @@ module Settingasm
# = Setting
#
# A simple settings solution using a YAML file. See README for more information.
- class Setting
+ class Settings
class << self
def name # :nodoc:
if instance._settings.key?("name")
@@ -31,10 +31,10 @@ def method_missing(name, *args, &block)
# Initializes a new settings object. You can initialize an object in any of the following ways:
#
- # Setting.new(:application) # will look for config/application.yml
- # Setting.new("application.yaml") # will look for application.yaml
- # Setting.new("/var/configs/application.yml") # will look for /var/configs/application.yml
- # Setting.new(:config1 => 1, :config2 => 2)
+ # Settings.new(:application) # will look for config/application.yml
+ # Settings.new("application.yaml") # will look for application.yaml
+ # Settings.new("/var/configs/application.yml") # will look for /var/configs/application.yml
+ # Settings.new(:config1 => 1, :config2 => 2)
#
# Basically if you pass a symbol it will look for that file in the configs directory of your rails app, if you are using this in rails. If you pass a string it should be an absolute path to your settings file.
# Then you can pass a hash, and it just allows you to access the hash via methods.
View
@@ -1,25 +1,14 @@
require File.dirname(__FILE__) + '/test_helper.rb'
class TestConfig < Test::Unit::TestCase
- def test_class_name
- Settingasm::Config.configure do |config|
- config.class_name = "Conf"
- end
-
- assert_equal Conf, Conf.setting1.class
- assert_equal "saweet", Conf.setting1.setting1_child
- assert_equal 5, Conf.setting2
- assert_equal 25, Conf.setting3
- end
-
def test_settings_file
Settingasm::Config.configure do |config|
config.settings_file = File.dirname(__FILE__) + '/application2.yml'
end
- Setting.reset!
- assert_equal "BenJohnson", Setting.neat.cool.awesome
- assert_equal 5, Setting.silly
- assert_equal 25, Setting.fun
+ Settings.reset!
+ assert_equal "BenJohnson", Settings.neat.cool.awesome
+ assert_equal 5, Settings.silly
+ assert_equal 25, Settings.fun
end
end
View
@@ -6,7 +6,6 @@
class Test::Unit::TestCase
def configure
Settingasm::Config.configure do |config|
- config.class_name = "Setting" unless defined?(::Setting)
config.settings_file = File.dirname(__FILE__) + "/application.yml"
end
end
@@ -17,6 +16,6 @@ def setup
def teardown
configure
- Settingasm::Setting.reset!
+ Settingasm::Settings.reset!
end
end
View
@@ -2,27 +2,27 @@
class TestSetting < Test::Unit::TestCase
def test_singleton_access
- assert_equal Setting, Setting.setting1.class
- assert_equal "saweet", Setting.setting1.setting1_child
- assert_equal 5, Setting.setting2
- assert_equal 25, Setting.setting3
+ assert_equal Settings, Settings.setting1.class
+ assert_equal "saweet", Settings.setting1.setting1_child
+ assert_equal 5, Settings.setting2
+ assert_equal 25, Settings.setting3
end
def test_instances
- settings1 = Setting.new(File.dirname(__FILE__) + '/application.yml')
+ settings1 = Settings.new(File.dirname(__FILE__) + '/application.yml')
assert_equal "saweet", settings1.setting1.setting1_child
assert_equal 5, settings1.setting2
assert_equal 25, settings1.setting3
- settings2 = Setting.new(File.dirname(__FILE__) + '/application2.yml')
+ settings2 = Settings.new(File.dirname(__FILE__) + '/application2.yml')
assert_equal "BenJohnson", settings2.neat.cool.awesome
assert_equal 5, settings2.silly
assert_equal 25, settings2.fun
end
def test_method_missing
- assert_raise(NoMethodError) { Setting.doesnt_exist }
- settings1 = Setting.new(File.dirname(__FILE__) + '/application.yml')
+ assert_raise(NoMethodError) { Settings.doesnt_exist }
+ settings1 = Settings.new(File.dirname(__FILE__) + '/application.yml')
assert_raise(NoMethodError) { settings1.doesnt_exist }
end
end

0 comments on commit aee3f70

Please sign in to comment.