youthtree-settings 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/Rakefile CHANGED
@@ -1,56 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
+ require 'bundler/gem_tasks'
3
4
 
4
5
  require 'active_support'
5
6
  require 'active_support/core_ext'
6
7
  require File.expand_path('lib/youth_tree/settings', File.dirname(__FILE__))
7
-
8
- begin
9
- require 'jeweler'
10
- Jeweler::Tasks.new do |gem|
11
- gem.name = "youthtree-settings"
12
- gem.summary = "Simple Settings for Rails Applications"
13
- gem.description = %Q{Lets you use config/settings.yml in a rails application to manage settings on a per-env basis.}
14
- gem.email = "sutto@sutto.net"
15
- gem.homepage = "http://github.com/YouthTree/youthtree-settings"
16
- gem.authors = ["Darcy Laycock"]
17
- gem.version = YouthTree::Settings::VERSION
18
- gem.add_dependency "activesupport", "~> 3.0.1"
19
- end
20
- Jeweler::GemcutterTasks.new
21
- rescue LoadError
22
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
- end
24
-
25
- require 'rake/testtask'
26
- Rake::TestTask.new(:test) do |test|
27
- test.libs << 'lib' << 'test'
28
- test.pattern = 'test/**/*_test.rb'
29
- test.verbose = true
30
- end
31
-
32
- begin
33
- require 'rcov/rcovtask'
34
- Rcov::RcovTask.new do |test|
35
- test.libs << 'test'
36
- test.pattern = 'test/**/*_test.rb'
37
- test.verbose = true
38
- end
39
- rescue LoadError
40
- task :rcov do
41
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
42
- end
43
- end
44
-
45
- task :test => :check_dependencies
46
-
47
- task :default => :test
48
-
49
- require 'rake/rdoctask'
50
- Rake::RDocTask.new do |rdoc|
51
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
52
- rdoc.rdoc_dir = 'rdoc'
53
- rdoc.title = "youthtree-settings #{version}"
54
- rdoc.rdoc_files.include('README*')
55
- rdoc.rdoc_files.include('lib/**/*.rb')
56
- end
@@ -4,12 +4,7 @@ require 'erb'
4
4
  module YouthTree
5
5
  class Settings
6
6
 
7
- VERSION = "0.3.0".freeze
8
-
9
- cattr_reader :settings_path
10
- def self.settings_path
11
- @@settings_path ||= Rails.root.join("config", "settings.yml")
12
- end
7
+ VERSION = "1.0.0".freeze
13
8
 
14
9
  def initialize(hash = {})
15
10
  @hash = Hash.new { |h,k| h[k] = self.class.new }
@@ -64,24 +59,36 @@ module YouthTree
64
59
 
65
60
  class << self
66
61
 
62
+ def setup(value = nil, &blk)
63
+ @@setup_callback = (blk || value)
64
+ end
65
+
66
+ def settings_path
67
+ @@settings_path ||= Rails.root.join("config", "settings.yml").to_s
68
+ end
69
+
67
70
  def load_from_file
68
- contents = File.read(self.settings_path)
71
+ if !File.readable?(settings_path)
72
+ $stderr.puts "Unable to load settings from #{settings_path} - Please check it exists and is readable."
73
+ return {}
74
+ end
75
+ # Otherwise, try loading...
76
+ contents = File.read(settings_path)
69
77
  contents = ERB.new(contents).result
70
78
  contents = YAML.load(contents)
71
79
  (contents["default"] || {}).deep_merge(contents[Rails.env] || {})
72
80
  end
73
81
 
74
82
  def default
75
- @@__default ||= begin
76
- groups = [load_from_file]
77
- self.new(groups.inject({}) { |a,v| a.deep_merge(v) })
78
- end
83
+ @@default ||= new(load_from_file)
79
84
  end
80
85
 
81
86
  def reset!
82
- @@__default = nil
87
+ @@default = nil
83
88
  default # Force us to reload the settings
84
89
  YouthTree::Settings.setup_mailer!
90
+ # If a setup block is defined, call it post configuration.
91
+ @setup_callback.call if defined?(@setup_callback) && @setup_callback
85
92
  true
86
93
  end
87
94
 
@@ -1,45 +1,20 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
5
2
 
3
+ require File.expand_path('lib/youth_tree/settings', File.dirname(__FILE__))
4
+
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{youthtree-settings}
8
- s.version = "0.3.0"
9
6
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Darcy Laycock"]
12
- s.date = %q{2011-05-17}
13
- s.description = %q{Lets you use config/settings.yml in a rails application to manage settings on a per-env basis.}
14
- s.email = %q{sutto@sutto.net}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.md"
18
- ]
19
- s.files = [
20
- ".document",
21
- "LICENSE",
22
- "README.md",
23
- "Rakefile",
24
- "lib/youth_tree/settings.rb",
25
- "lib/youthtree-settings.rb",
26
- "youthtree-settings.gemspec"
27
- ]
28
- s.homepage = %q{http://github.com/YouthTree/youthtree-settings}
7
+ s.name = "youthtree-settings"
8
+ s.summary = "Simple Settings for Rails Applications"
9
+ s.description = %Q{Lets you use config/settings.yml in a rails application to manage settings on a per-env basis.}
10
+ s.authors = ["Darcy Laycock"]
11
+ s.email = ["sutto@sutto.net"]
12
+ s.homepage = "http://github.com/YouthTree/youthtree-settings"
13
+ s.files = `git ls-files`.split($\)
14
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
29
16
  s.require_paths = ["lib"]
30
- s.rubygems_version = %q{1.6.2}
31
- s.summary = %q{Simple Settings for Rails Applications}
32
-
33
- if s.respond_to? :specification_version then
34
- s.specification_version = 3
35
-
36
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
37
- s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.1"])
38
- else
39
- s.add_dependency(%q<activesupport>, ["~> 3.0.1"])
40
- end
41
- else
42
- s.add_dependency(%q<activesupport>, ["~> 3.0.1"])
43
- end
44
- end
17
+ s.version = YouthTree::Settings::VERSION.dup
18
+ s.add_dependency "activesupport", "~> 3.0.1"
45
19
 
20
+ end
metadata CHANGED
@@ -1,89 +1,70 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: youthtree-settings
3
- version: !ruby/object:Gem::Version
4
- hash: 19
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 0
10
- version: 0.3.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Darcy Laycock
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-05-17 00:00:00 +08:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-04-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: activesupport
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 5
30
- segments:
31
- - 3
32
- - 0
33
- - 1
20
+ - !ruby/object:Gem::Version
34
21
  version: 3.0.1
35
22
  type: :runtime
36
- version_requirements: *id001
37
- description: Lets you use config/settings.yml in a rails application to manage settings on a per-env basis.
38
- email: sutto@sutto.net
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.1
30
+ description: Lets you use config/settings.yml in a rails application to manage settings
31
+ on a per-env basis.
32
+ email:
33
+ - sutto@sutto.net
39
34
  executables: []
40
-
41
35
  extensions: []
42
-
43
- extra_rdoc_files:
44
- - LICENSE
45
- - README.md
46
- files:
36
+ extra_rdoc_files: []
37
+ files:
47
38
  - .document
39
+ - .gitignore
48
40
  - LICENSE
49
41
  - README.md
50
42
  - Rakefile
51
43
  - lib/youth_tree/settings.rb
52
44
  - lib/youthtree-settings.rb
53
45
  - youthtree-settings.gemspec
54
- has_rdoc: true
55
46
  homepage: http://github.com/YouthTree/youthtree-settings
56
47
  licenses: []
57
-
58
48
  post_install_message:
59
49
  rdoc_options: []
60
-
61
- require_paths:
50
+ require_paths:
62
51
  - lib
63
- required_ruby_version: !ruby/object:Gem::Requirement
52
+ required_ruby_version: !ruby/object:Gem::Requirement
64
53
  none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- hash: 3
69
- segments:
70
- - 0
71
- version: "0"
72
- required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
59
  none: false
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- hash: 3
78
- segments:
79
- - 0
80
- version: "0"
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
81
64
  requirements: []
82
-
83
65
  rubyforge_project:
84
- rubygems_version: 1.6.2
66
+ rubygems_version: 1.8.21
85
67
  signing_key:
86
68
  specification_version: 3
87
69
  summary: Simple Settings for Rails Applications
88
70
  test_files: []
89
-