simple-settings 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +24 -0
- data/Rakefile +27 -0
- data/lib/simple-settings/version.rb +3 -0
- data/lib/simple-settings.rb +42 -0
- metadata +51 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
= SimpleSettings
|
2
|
+
|
3
|
+
A gem for managing a settings file.
|
4
|
+
|
5
|
+
http://fury-badge.herokuapp.com/rb/simple-settings.png
|
6
|
+
|
7
|
+
{<img src="https://travis-ci.org/aosmith/simple-settings.png?branch=master" />}[https://travis-ci.org/aosmith/simple-settings?branch=master]
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
At some point you'll need to load settings. In a rails project I'd do this in config/initializers/01_settings.rb:
|
12
|
+
|
13
|
+
SimpleSettings.load
|
14
|
+
|
15
|
+
If you're not using a rails project you'll need to set the location of the settings.yml and your current environment via:
|
16
|
+
|
17
|
+
SimpleSettings.file_path = "~/path_to/settings.yml"
|
18
|
+
SimpleSettings.env = "development"
|
19
|
+
|
20
|
+
Your yaml file will be available via:
|
21
|
+
|
22
|
+
SimpleSettings[:setting_name]
|
23
|
+
SimpleSettings[:nested_attributes][:work_too]
|
24
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'MantraSettings'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "mantra-settings/version"
|
2
|
+
|
3
|
+
module SimpleSettings
|
4
|
+
@env = false
|
5
|
+
@file_path = false
|
6
|
+
@config = {}
|
7
|
+
class << self
|
8
|
+
attr_accessor :config, :file_path, :env
|
9
|
+
def load
|
10
|
+
begin
|
11
|
+
@config = YAML::load(File.open(file_path))[env].symbolize_keys
|
12
|
+
rescue
|
13
|
+
l = Logger.new(STDERR)
|
14
|
+
l.error "Failed loading settings file: #{file_path} for env: #{env}"
|
15
|
+
@config = {}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def file_path
|
20
|
+
return @file_path if @file_path
|
21
|
+
return @file_path = Rails.root.join('config','settings.yml') if Rails.root
|
22
|
+
end
|
23
|
+
|
24
|
+
def env
|
25
|
+
return @env if @env
|
26
|
+
return @env = Rails.env
|
27
|
+
end
|
28
|
+
end
|
29
|
+
class Hash
|
30
|
+
def symbolize_keys
|
31
|
+
arr = {}
|
32
|
+
self.each do |k,v|
|
33
|
+
if v.is_a? Hash
|
34
|
+
arr[k.to_sym] = v.symbolize_keys!
|
35
|
+
else
|
36
|
+
arr[k.to_sym] = v
|
37
|
+
end
|
38
|
+
end
|
39
|
+
arr
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple-settings
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alex Smith
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-13 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ''
|
15
|
+
email:
|
16
|
+
- aosmith@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/simple-settings/version.rb
|
22
|
+
- lib/simple-settings.rb
|
23
|
+
- MIT-LICENSE
|
24
|
+
- Rakefile
|
25
|
+
- README.rdoc
|
26
|
+
homepage: http://alexsmith.io
|
27
|
+
licenses: []
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubyforge_project:
|
46
|
+
rubygems_version: 1.8.25
|
47
|
+
signing_key:
|
48
|
+
specification_version: 3
|
49
|
+
summary: A gem to easily handle environment specific settings
|
50
|
+
test_files: []
|
51
|
+
has_rdoc:
|