youthtree-settings 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +27 -0
- data/README.md +65 -0
- data/Rakefile +56 -0
- data/lib/youth_tree/settings.rb +141 -0
- data/lib/youthtree-settings.rb +3 -0
- metadata +90 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Copyright (c) 2010, Youth Tree
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
1. Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
2. Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
3. All advertising materials mentioning features or use of this software
|
12
|
+
must display the following acknowledgement:
|
13
|
+
This product includes software developed by the Youth Tree.
|
14
|
+
4. Neither the name of the Youth Tree nor the
|
15
|
+
names of its contributors may be used to endorse or promote products
|
16
|
+
derived from this software without specific prior written permission.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY YOUTH TREE ''AS IS'' AND ANY
|
19
|
+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
20
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL YOUTH TREE BE LIABLE FOR ANY
|
22
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
23
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
24
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
25
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
26
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
27
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# YouthTree Settings #
|
2
|
+
|
3
|
+
## Installation ##
|
4
|
+
|
5
|
+
1. Add "gem 'youthtree-settings' to your Gemfile"
|
6
|
+
2. Run bundle install
|
7
|
+
|
8
|
+
## Usage ##
|
9
|
+
|
10
|
+
Simply add the gem,file in your `config/settings.yml`
|
11
|
+
and use on the Settings object. Note that you can use:
|
12
|
+
|
13
|
+
* `Setting.name` - base
|
14
|
+
* `Setting.name.other` - nested
|
15
|
+
* `Setting.name.other?` - check for a key
|
16
|
+
|
17
|
+
## Configuration ##
|
18
|
+
|
19
|
+
Simply put a yaml file in `config/settings.yml`. As an example:
|
20
|
+
|
21
|
+
---
|
22
|
+
default:
|
23
|
+
some_key: 1
|
24
|
+
nested: true
|
25
|
+
production:
|
26
|
+
google_analytics:
|
27
|
+
identifier: "UA-XXXXXXXX-X"
|
28
|
+
mailer:
|
29
|
+
contact_email: "team@site.com"
|
30
|
+
from: "noreply@site.com"
|
31
|
+
host: "site.com"
|
32
|
+
delivery_method: smtp
|
33
|
+
smtp_settings:
|
34
|
+
address: smtp.gmail.com
|
35
|
+
port: 587
|
36
|
+
authentication: plain
|
37
|
+
enable_starttls_auto: true
|
38
|
+
domain: site.com
|
39
|
+
user_name: user@site.com
|
40
|
+
password: yourpassword
|
41
|
+
development:
|
42
|
+
mailer:
|
43
|
+
contact_email: "test@site.dev"
|
44
|
+
from: "test@site.dev"
|
45
|
+
host: "localhost:3000"
|
46
|
+
delivery_method: sendmail
|
47
|
+
test:
|
48
|
+
mailer:
|
49
|
+
contact_email: "example@example.com"
|
50
|
+
from: "example@example.com"
|
51
|
+
host: "example.com"
|
52
|
+
delivery_method: test
|
53
|
+
|
54
|
+
|
55
|
+
## Note on Patches/Pull Requests ##
|
56
|
+
|
57
|
+
1. Fork the project.
|
58
|
+
2. Make your feature addition or bug fix.
|
59
|
+
3. Add tests for it. This is important so I don't break it in a future version unintentionally.
|
60
|
+
4. Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
61
|
+
5. Send me a pull request. Bonus points for topic branches.
|
62
|
+
|
63
|
+
## Copyright ##
|
64
|
+
|
65
|
+
Copyright (c) 2010 Youth Tree. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
require 'active_support'
|
5
|
+
require 'active_support/core_ext'
|
6
|
+
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.0.beta4"
|
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
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module YouthTree
|
4
|
+
class Settings
|
5
|
+
|
6
|
+
VERSION = "0.1.0".freeze
|
7
|
+
|
8
|
+
cattr_reader :settings_path
|
9
|
+
def self.settings_path
|
10
|
+
@@settings_path ||= Rails.root.join("config", "settings.yml")
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(hash = {})
|
14
|
+
@hash = Hash.new { |h,k| h[k] = self.class.new }
|
15
|
+
hash.each_pair { |k, v| self[k] = v }
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_hash
|
19
|
+
unpack_attr @hash
|
20
|
+
end
|
21
|
+
|
22
|
+
def []=(k, v)
|
23
|
+
@hash[k.to_sym] = normalize_attr(v)
|
24
|
+
end
|
25
|
+
|
26
|
+
def [](k)
|
27
|
+
@hash[k.to_sym]
|
28
|
+
end
|
29
|
+
|
30
|
+
def has?(key)
|
31
|
+
key = key.to_sym
|
32
|
+
@hash.has_key?(key) && @hash[key].present?
|
33
|
+
end
|
34
|
+
|
35
|
+
def blank?
|
36
|
+
@hash.blank?
|
37
|
+
end
|
38
|
+
|
39
|
+
def present?
|
40
|
+
!blank?
|
41
|
+
end
|
42
|
+
|
43
|
+
def method_missing(name, *args, &blk)
|
44
|
+
name = name.to_s
|
45
|
+
key, modifier = name[0..-2], name[-1, 1]
|
46
|
+
case modifier
|
47
|
+
when '?'
|
48
|
+
has?(key)
|
49
|
+
when '='
|
50
|
+
send(:[]=, key, *args)
|
51
|
+
else
|
52
|
+
self[name]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def respond_to?(name, key = false)
|
57
|
+
true
|
58
|
+
end
|
59
|
+
|
60
|
+
class << self
|
61
|
+
|
62
|
+
def load_from_file
|
63
|
+
contents = YAML.load(File.read(self.settings_path))
|
64
|
+
(contents["default"] || {}).deep_merge(contents[Rails.env] || {})
|
65
|
+
end
|
66
|
+
|
67
|
+
def default
|
68
|
+
@@__default ||= begin
|
69
|
+
groups = [load_from_file]
|
70
|
+
self.new(groups.inject({}) { |a,v| a.deep_merge(v) })
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def method_missing(name, *args, &blk)
|
75
|
+
default.send(name, *args, &blk)
|
76
|
+
end
|
77
|
+
|
78
|
+
def respond_to?(name, key = false)
|
79
|
+
true
|
80
|
+
end
|
81
|
+
|
82
|
+
def ssl?
|
83
|
+
!disable_ssl? && (force_ssl? || Rails.env.production?)
|
84
|
+
end
|
85
|
+
|
86
|
+
def ssl_protocol
|
87
|
+
ssl? ? "https" : "http"
|
88
|
+
end
|
89
|
+
|
90
|
+
# Sets up ActionMailer to use settings from Settings.
|
91
|
+
def setup_mailer!
|
92
|
+
return unless mailer?
|
93
|
+
s = mailer
|
94
|
+
ActionMailer::Base.default_url_options[:host] = s.host
|
95
|
+
ActionMailer::Base.delivery_method = s.delivery_method.to_sym
|
96
|
+
ActionMailer::Base.smtp_settings = s.smtp_settings.to_hash if s.smtp_settings?
|
97
|
+
ActionMailer::Base.sendmail_settings = s.sendmail_settings.to_hash if s.sendmail_settings?
|
98
|
+
ActionMailer::Base.default :from => s.from
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
protected
|
104
|
+
|
105
|
+
def normalize_attr(value)
|
106
|
+
case value
|
107
|
+
when Hash
|
108
|
+
self.class.new(value)
|
109
|
+
when Array
|
110
|
+
value.map { |v| normalize_attr(v) }
|
111
|
+
else
|
112
|
+
value
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def unpack_attr(value)
|
117
|
+
case value
|
118
|
+
when self.class
|
119
|
+
value.to_hash
|
120
|
+
when Hash
|
121
|
+
returning({}) do |h|
|
122
|
+
value.each_pair { |k,v| h[k] = unpack_attr(v) }
|
123
|
+
end
|
124
|
+
when Array
|
125
|
+
value.map { |v| unpack_attr(v) }
|
126
|
+
else
|
127
|
+
value
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
if defined?(Rails::Railtie)
|
134
|
+
class Railtie < Rails::Railtie
|
135
|
+
initializer "youthtree.settings" do
|
136
|
+
YouthTree::Settings.setup_mailer!
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: youthtree-settings
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Darcy Laycock
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-07-08 00:00:00 +08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: activesupport
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: -1848230024
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
- 0
|
34
|
+
- beta4
|
35
|
+
version: 3.0.0.beta4
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
description: Lets you use config/settings.yml in a rails application to manage settings on a per-env basis.
|
39
|
+
email: sutto@sutto.net
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- LICENSE
|
46
|
+
- README.md
|
47
|
+
files:
|
48
|
+
- .document
|
49
|
+
- .gitignore
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/youth_tree/settings.rb
|
54
|
+
- lib/youthtree-settings.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/YouthTree/youthtree-settings
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --charset=UTF-8
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.3.7
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Simple Settings for Rails Applications
|
89
|
+
test_files: []
|
90
|
+
|