settingslogic 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/{MIT-LICENSE → LICENSE} +0 -0
- data/Rakefile +47 -18
- data/VERSION.yml +4 -0
- data/init.rb +1 -1
- data/lib/settingslogic/settings.rb +7 -1
- data/rails/init.rb +1 -0
- data/settingslogic.gemspec +59 -0
- data/test/application3.yml +9 -0
- data/test/{test_config.rb → config_test.rb} +0 -0
- data/test/{test_setting.rb → setting_test.rb} +20 -0
- data/test/test_helper.rb +6 -0
- metadata +21 -26
- data/Manifest.txt +0 -15
- data/lib/settingslogic/version.rb +0 -54
data/.gitignore
ADDED
data/{MIT-LICENSE → LICENSE}
RENAMED
File without changes
|
data/Rakefile
CHANGED
@@ -1,20 +1,49 @@
|
|
1
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
2
3
|
|
3
|
-
|
4
|
-
require
|
5
|
-
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "settingslogic"
|
8
|
+
gem.summary = "A simple and straightforward settings solution that uses an ERB enabled YAML file and a singleton design pattern."
|
9
|
+
gem.email = "bjohnson@binarylogic.com"
|
10
|
+
gem.homepage = "http://github.com/binarylogic/settingslogic"
|
11
|
+
gem.authors = ["Ben Johnson of Binary Logic"]
|
12
|
+
gem.rubyforge_project = "settingslogic"
|
13
|
+
gem.add_dependency "activesupport"
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
6
18
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
19
|
+
require 'rake/testtask'
|
20
|
+
Rake::TestTask.new(:test) do |test|
|
21
|
+
test.libs << 'lib' << 'test'
|
22
|
+
test.pattern = 'test/**/*_test.rb'
|
23
|
+
test.verbose = true
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'rcov/rcovtask'
|
28
|
+
Rcov::RcovTask.new do |test|
|
29
|
+
test.libs << 'test'
|
30
|
+
test.pattern = 'test/**/*_test.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
task :rcov do
|
35
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :test
|
40
|
+
|
41
|
+
begin
|
42
|
+
require 'rake/contrib/sshpublisher'
|
43
|
+
namespace :rubyforge do
|
44
|
+
desc "Release gem to RubyForge"
|
45
|
+
task :release => ["rubyforge:release:gem"]
|
46
|
+
end
|
47
|
+
rescue LoadError
|
48
|
+
puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
|
49
|
+
end
|
data/VERSION.yml
ADDED
data/init.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require "
|
1
|
+
require File.dirname(__FILE__) + "/rails/init.rb"
|
@@ -40,10 +40,13 @@ module Settingslogic
|
|
40
40
|
root_path = defined?(RAILS_ROOT) ? "#{RAILS_ROOT}/config/" : ""
|
41
41
|
file_path = name_or_hash.is_a?(Symbol) ? "#{root_path}#{name_or_hash}.yml" : name_or_hash
|
42
42
|
self.update YAML.load(ERB.new(File.read(file_path)).result).to_hash
|
43
|
-
self.update self[RAILS_ENV] if defined?(RAILS_ENV)
|
44
43
|
else
|
45
44
|
raise ArgumentError.new("Your settings must be a hash, a symbol representing the name of the .yml file in your config directory, or a string representing the abosolute path to your settings file.")
|
46
45
|
end
|
46
|
+
if defined?(RAILS_ENV)
|
47
|
+
rails_env = self.keys.include?(RAILS_ENV) ? RAILS_ENV : RAILS_ENV.to_sym
|
48
|
+
self.update self[rails_env] if self[rails_env]
|
49
|
+
end
|
47
50
|
define_settings!
|
48
51
|
end
|
49
52
|
|
@@ -66,6 +69,9 @@ module Settingslogic
|
|
66
69
|
def #{key}
|
67
70
|
@#{key} ||= self[#{key.inspect}]
|
68
71
|
end
|
72
|
+
def #{key}=(value)
|
73
|
+
@#{key} = value
|
74
|
+
end
|
69
75
|
end_eval
|
70
76
|
end
|
71
77
|
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "settingslogic"
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{settingslogic}
|
5
|
+
s.version = "1.0.4"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Ben Johnson of Binary Logic"]
|
9
|
+
s.date = %q{2009-06-28}
|
10
|
+
s.email = %q{bjohnson@binarylogic.com}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".gitignore",
|
17
|
+
"CHANGELOG.rdoc",
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION.yml",
|
22
|
+
"init.rb",
|
23
|
+
"lib/settingslogic.rb",
|
24
|
+
"lib/settingslogic/config.rb",
|
25
|
+
"lib/settingslogic/settings.rb",
|
26
|
+
"rails/init.rb",
|
27
|
+
"settingslogic.gemspec",
|
28
|
+
"test/application.yml",
|
29
|
+
"test/application2.yml",
|
30
|
+
"test/application3.yml",
|
31
|
+
"test/config_test.rb",
|
32
|
+
"test/setting_test.rb",
|
33
|
+
"test/test_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/binarylogic/settingslogic}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubyforge_project = %q{settingslogic}
|
39
|
+
s.rubygems_version = %q{1.3.4}
|
40
|
+
s.summary = %q{A simple and straightforward settings solution that uses an ERB enabled YAML file and a singleton design pattern.}
|
41
|
+
s.test_files = [
|
42
|
+
"test/config_test.rb",
|
43
|
+
"test/setting_test.rb",
|
44
|
+
"test/test_helper.rb"
|
45
|
+
]
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
58
|
+
end
|
59
|
+
end
|
File without changes
|
@@ -40,4 +40,24 @@ class TestSetting < Test::Unit::TestCase
|
|
40
40
|
assert_equal 5, settings1.silly
|
41
41
|
assert_equal 25, settings1.fun
|
42
42
|
end
|
43
|
+
|
44
|
+
def test_environment_specific_settings
|
45
|
+
in_test_environment do
|
46
|
+
settings1 = Settings.new(File.dirname(__FILE__) + '/application3.yml')
|
47
|
+
assert_equal 25, settings1.fun
|
48
|
+
assert_equal "test_specific", settings1.silly
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_environment_specific_settings_when_initialized_with_hash
|
53
|
+
in_test_environment do
|
54
|
+
settings1 = Settings.new(
|
55
|
+
:silly => 5,
|
56
|
+
'fun' => 25,
|
57
|
+
:test => { :silly => "test_specific" }
|
58
|
+
)
|
59
|
+
assert_equal 25, settings1.fun
|
60
|
+
assert_equal "test_specific", settings1.silly
|
61
|
+
end
|
62
|
+
end
|
43
63
|
end
|
data/test/test_helper.rb
CHANGED
@@ -18,4 +18,10 @@ class Test::Unit::TestCase
|
|
18
18
|
configure
|
19
19
|
Settingslogic::Settings.reset!
|
20
20
|
end
|
21
|
+
|
22
|
+
def in_test_environment(&block)
|
23
|
+
Settingslogic::Settings.const_set :RAILS_ENV, "test"
|
24
|
+
block.call
|
25
|
+
Settingslogic::Settings.send :remove_const, :RAILS_ENV
|
26
|
+
end
|
21
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: settingslogic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Johnson of Binary Logic
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-28 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,48 +22,41 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: "0"
|
24
24
|
version:
|
25
|
-
|
26
|
-
name: hoe
|
27
|
-
type: :development
|
28
|
-
version_requirement:
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.12.1
|
34
|
-
version:
|
35
|
-
description: A simple and straightforward settings solution that uses an ERB enabled YAML file and a singleton design pattern.
|
25
|
+
description:
|
36
26
|
email: bjohnson@binarylogic.com
|
37
27
|
executables: []
|
38
28
|
|
39
29
|
extensions: []
|
40
30
|
|
41
31
|
extra_rdoc_files:
|
42
|
-
-
|
43
|
-
- CHANGELOG.rdoc
|
32
|
+
- LICENSE
|
44
33
|
- README.rdoc
|
45
34
|
files:
|
35
|
+
- .gitignore
|
46
36
|
- CHANGELOG.rdoc
|
47
|
-
-
|
48
|
-
- Manifest.txt
|
37
|
+
- LICENSE
|
49
38
|
- README.rdoc
|
50
39
|
- Rakefile
|
40
|
+
- VERSION.yml
|
51
41
|
- init.rb
|
52
42
|
- lib/settingslogic.rb
|
53
43
|
- lib/settingslogic/config.rb
|
54
44
|
- lib/settingslogic/settings.rb
|
55
|
-
-
|
45
|
+
- rails/init.rb
|
46
|
+
- settingslogic.gemspec
|
56
47
|
- test/application.yml
|
57
48
|
- test/application2.yml
|
58
|
-
- test/
|
49
|
+
- test/application3.yml
|
50
|
+
- test/config_test.rb
|
51
|
+
- test/setting_test.rb
|
59
52
|
- test/test_helper.rb
|
60
|
-
- test/test_setting.rb
|
61
53
|
has_rdoc: true
|
62
54
|
homepage: http://github.com/binarylogic/settingslogic
|
55
|
+
licenses: []
|
56
|
+
|
63
57
|
post_install_message:
|
64
58
|
rdoc_options:
|
65
|
-
- --
|
66
|
-
- README.rdoc
|
59
|
+
- --charset=UTF-8
|
67
60
|
require_paths:
|
68
61
|
- lib
|
69
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -81,9 +74,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
74
|
requirements: []
|
82
75
|
|
83
76
|
rubyforge_project: settingslogic
|
84
|
-
rubygems_version: 1.3.
|
77
|
+
rubygems_version: 1.3.4
|
85
78
|
signing_key:
|
86
|
-
specification_version:
|
79
|
+
specification_version: 3
|
87
80
|
summary: A simple and straightforward settings solution that uses an ERB enabled YAML file and a singleton design pattern.
|
88
|
-
test_files:
|
89
|
-
|
81
|
+
test_files:
|
82
|
+
- test/config_test.rb
|
83
|
+
- test/setting_test.rb
|
84
|
+
- test/test_helper.rb
|
data/Manifest.txt
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
CHANGELOG.rdoc
|
2
|
-
MIT-LICENSE
|
3
|
-
Manifest.txt
|
4
|
-
README.rdoc
|
5
|
-
Rakefile
|
6
|
-
init.rb
|
7
|
-
lib/settingslogic.rb
|
8
|
-
lib/settingslogic/config.rb
|
9
|
-
lib/settingslogic/settings.rb
|
10
|
-
lib/settingslogic/version.rb
|
11
|
-
test/application.yml
|
12
|
-
test/application2.yml
|
13
|
-
test/test_config.rb
|
14
|
-
test/test_helper.rb
|
15
|
-
test/test_setting.rb
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module Settingslogic
|
2
|
-
# A class for describing the current version of a library. The version
|
3
|
-
# consists of three parts: the +major+ number, the +minor+ number, and the
|
4
|
-
# +tiny+ (or +patch+) number.
|
5
|
-
class Version
|
6
|
-
|
7
|
-
include Comparable
|
8
|
-
|
9
|
-
# A convenience method for instantiating a new Version instance with the
|
10
|
-
# given +major+, +minor+, and +tiny+ components.
|
11
|
-
def self.[](major, minor, tiny)
|
12
|
-
new(major, minor, tiny)
|
13
|
-
end
|
14
|
-
|
15
|
-
attr_reader :major, :minor, :tiny
|
16
|
-
|
17
|
-
# Create a new Version object with the given components.
|
18
|
-
def initialize(major, minor, tiny)
|
19
|
-
@major, @minor, @tiny = major, minor, tiny
|
20
|
-
end
|
21
|
-
|
22
|
-
# Compare this version to the given +version+ object.
|
23
|
-
def <=>(version)
|
24
|
-
to_i <=> version.to_i
|
25
|
-
end
|
26
|
-
|
27
|
-
# Converts this version object to a string, where each of the three
|
28
|
-
# version components are joined by the '.' character. E.g., 2.0.0.
|
29
|
-
def to_s
|
30
|
-
@to_s ||= [@major, @minor, @tiny].join(".")
|
31
|
-
end
|
32
|
-
|
33
|
-
# Converts this version to a canonical integer that may be compared
|
34
|
-
# against other version objects.
|
35
|
-
def to_i
|
36
|
-
@to_i ||= @major * 1_000_000 + @minor * 1_000 + @tiny
|
37
|
-
end
|
38
|
-
|
39
|
-
def to_a
|
40
|
-
[@major, @minor, @tiny]
|
41
|
-
end
|
42
|
-
|
43
|
-
MAJOR = 1
|
44
|
-
MINOR = 0
|
45
|
-
TINY = 3
|
46
|
-
|
47
|
-
# The current version as a Version instance
|
48
|
-
CURRENT = new(MAJOR, MINOR, TINY)
|
49
|
-
# The current version as a String
|
50
|
-
STRING = CURRENT.to_s
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|