figleaf 0.0.1
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/.gitignore +32 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +73 -0
- data/Rakefile +21 -0
- data/figleaf.gemspec +23 -0
- data/lib/figleaf/settings.rb +78 -0
- data/lib/figleaf/version.rb +3 -0
- data/lib/figleaf.rb +4 -0
- data/spec/settings_spec.rb +92 -0
- data/spec/spec_helper.rb +20 -0
- metadata +107 -0
data/.gitignore
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
**.orig
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
*.sassc
|
5
|
+
.bundle
|
6
|
+
.config
|
7
|
+
.rspec
|
8
|
+
.sass-cache
|
9
|
+
.yardoc
|
10
|
+
/.bundle
|
11
|
+
/coverage/
|
12
|
+
/db/*.sqlite3
|
13
|
+
/log/*
|
14
|
+
/public/system/*
|
15
|
+
/spec/tmp/*
|
16
|
+
/tmp/*
|
17
|
+
/vendor/bundle
|
18
|
+
Gemfile.lock
|
19
|
+
InstalledFiles
|
20
|
+
_yardoc
|
21
|
+
capybara-*.html
|
22
|
+
coverage
|
23
|
+
doc/
|
24
|
+
lib/bundler/man
|
25
|
+
pickle-email-*.html
|
26
|
+
pkg
|
27
|
+
rdoc
|
28
|
+
rerun.txt
|
29
|
+
spec/reports
|
30
|
+
test/tmp
|
31
|
+
test/version_tmp
|
32
|
+
tmp
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Juan C. Müller
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Settings
|
2
|
+
|
3
|
+
YAML based DRY settings manager.
|
4
|
+
|
5
|
+
The YAML expansion functionality came about by our getting tired of having to
|
6
|
+
create a YAML file and then create an initializer that would expand such file
|
7
|
+
and include in our applications.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'settings'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install settings
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
In `application.rb`:
|
26
|
+
|
27
|
+
```
|
28
|
+
Settings.configure_with_auto_define do |s|
|
29
|
+
s.env = Rails.env
|
30
|
+
s.some_awesome_flag = true
|
31
|
+
s.load_settings
|
32
|
+
end
|
33
|
+
```
|
34
|
+
Then, you can override any particular setting inside your environments/*.rb
|
35
|
+
files.
|
36
|
+
|
37
|
+
eg: In `production.rb`
|
38
|
+
```
|
39
|
+
Settings.configure do |s|
|
40
|
+
s.some_awesome_flag = false
|
41
|
+
end
|
42
|
+
```
|
43
|
+
etc...
|
44
|
+
|
45
|
+
Also, it provides the ability for you to define all your environment dependent
|
46
|
+
settings in just one YAML file inside `config/settings/`. The anatomy of these
|
47
|
+
files should be:
|
48
|
+
|
49
|
+
```
|
50
|
+
development:
|
51
|
+
foo: bar
|
52
|
+
|
53
|
+
test:
|
54
|
+
foo: flob
|
55
|
+
|
56
|
+
production:
|
57
|
+
foo: foo
|
58
|
+
```
|
59
|
+
|
60
|
+
The Settings parser will create a namespace for your YAML file after the file
|
61
|
+
name.
|
62
|
+
|
63
|
+
Then, assuming that you named your YAML file `mysetting.yml`. you can just
|
64
|
+
access `foo` as `Settings.mysetting["foo"]`. (Inspired by Rails' `database.yml`,
|
65
|
+
of course.)
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
1. Fork it
|
70
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
71
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
72
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
73
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
$:.push File.expand_path("../lib", __FILE__)
|
4
|
+
|
5
|
+
require "rspec/core/rake_task"
|
6
|
+
require "bundler/gem_tasks"
|
7
|
+
|
8
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
9
|
+
spec.pattern = "spec/**/*_spec.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Clean backup and swap files, and artifacts"
|
13
|
+
task :clean do
|
14
|
+
require "fileutils"
|
15
|
+
Dir["{pkg/*,**/*~,**/.*.sw?,coverage/**,spec/reports/**}"].each do |file|
|
16
|
+
rm_rf file
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Run rspec by default"
|
21
|
+
task :default => :spec
|
data/figleaf.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/figleaf/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Juan C. Müller"]
|
6
|
+
gem.email = ["jcmuller@gmail.com"]
|
7
|
+
gem.description = %q{YAML based DRY settings manager.}
|
8
|
+
gem.summary = %q{YAML based DRY settings manager.}
|
9
|
+
gem.homepage = "http://github.com/challengepost/figleaf"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "figleaf"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Figleaf::VERSION
|
17
|
+
|
18
|
+
%w(rake rspec).each do |g|
|
19
|
+
gem.add_development_dependency(g)
|
20
|
+
end
|
21
|
+
|
22
|
+
gem.add_dependency("activesupport")
|
23
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'active_support/core_ext/class'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
module Figleaf
|
6
|
+
class Settings
|
7
|
+
class_attribute :auto_define
|
8
|
+
self.auto_define = false
|
9
|
+
|
10
|
+
def self.configure_with_auto_define
|
11
|
+
self.auto_define.tap do |cached_auto_define|
|
12
|
+
self.auto_define = true
|
13
|
+
yield self
|
14
|
+
self.auto_define = cached_auto_define
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configure
|
19
|
+
self.auto_define.tap do |cached_auto_define|
|
20
|
+
self.auto_define = false
|
21
|
+
yield self
|
22
|
+
self.auto_define = cached_auto_define
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.override_with_local!(local_file)
|
27
|
+
#this file (i.e. test.local.rb) is an optional place to put settings
|
28
|
+
local_file.tap do |local_settings_path|
|
29
|
+
eval(IO.read(local_settings_path), binding) if File.exists?(local_settings_path)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.method_missing(method_name, *args)
|
34
|
+
if self.auto_define && method_name.to_s =~ /=$/ && args.length == 1
|
35
|
+
self.define_cattr_methods(method_name)
|
36
|
+
self.send(method_name, args.shift)
|
37
|
+
else
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.define_cattr_methods(setter_name)
|
43
|
+
getter_name = setter_name.to_s.gsub('=','')
|
44
|
+
|
45
|
+
cattr_writer getter_name
|
46
|
+
define_singleton_method(getter_name) do
|
47
|
+
result = class_variable_get "@@#{getter_name}"
|
48
|
+
result.respond_to?(:call) ? result.call : result
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Load all files in config/settings and set their contents as first level
|
53
|
+
# citizen of Settings:
|
54
|
+
# config/settings/some_service.yml contains
|
55
|
+
# production:
|
56
|
+
# foo: bar
|
57
|
+
# --> Settings.some_service.foo = bar
|
58
|
+
def self.load_settings
|
59
|
+
Dir.glob(root.join('config', 'settings', '*.yml')).each do |file|
|
60
|
+
property_name = File.basename(file, '.yml')
|
61
|
+
property = YAML.load_file(file)[env]
|
62
|
+
configure_with_auto_define do |s|
|
63
|
+
s.send("#{property_name}=", property)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.root
|
69
|
+
return Rails.root if defined?(Rails)
|
70
|
+
Pathname.new('.')
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.env
|
74
|
+
return Rails.env if defined?(Rails)
|
75
|
+
ENV['ENVIRONMENT']
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/figleaf.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'figleaf'
|
3
|
+
|
4
|
+
describe Figleaf::Settings do
|
5
|
+
|
6
|
+
describe "setters and getters" do
|
7
|
+
context "auto define enabled" do
|
8
|
+
before(:each) do
|
9
|
+
described_class.auto_define = true
|
10
|
+
end
|
11
|
+
it "should auto define methods and set initial value when setter used" do
|
12
|
+
described_class.fictional_feature_enabled = :on
|
13
|
+
described_class.fictional_feature_enabled.should == :on
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return result of proc when set as a proc" do
|
17
|
+
described_class.call_this_proc = -> { 3 }
|
18
|
+
described_class.call_this_proc.should == 3
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "auto define disabled" do
|
23
|
+
before(:each) do
|
24
|
+
described_class.auto_define = true
|
25
|
+
described_class.fictional_feature_enabled = :on
|
26
|
+
described_class.auto_define = false
|
27
|
+
end
|
28
|
+
it "should not auto defined setters and getters" do
|
29
|
+
lambda {
|
30
|
+
described_class.undefined_setting = :raises_error
|
31
|
+
}.should raise_error
|
32
|
+
|
33
|
+
lambda {
|
34
|
+
described_class.undefined_setting
|
35
|
+
}.should raise_error
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should set/get previous defined attributes" do
|
39
|
+
described_class.fictional_feature_enabled.should eq(:on)
|
40
|
+
|
41
|
+
described_class.fictional_feature_enabled = :off
|
42
|
+
described_class.fictional_feature_enabled.should eq(:off)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "self.configure_with_auto_define" do
|
48
|
+
it "should accept new setter values in block form" do
|
49
|
+
described_class.configure_with_auto_define do |s|
|
50
|
+
s.another_fictional_feature_mode = :admin
|
51
|
+
s.enable_fictional_activity_feed = true
|
52
|
+
end
|
53
|
+
|
54
|
+
described_class.another_fictional_feature_mode.should eq(:admin)
|
55
|
+
described_class.enable_fictional_activity_feed.should be_true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "self.configure" do
|
60
|
+
before(:each) do
|
61
|
+
described_class.auto_define = true
|
62
|
+
described_class.fictional_feature_enabled = :on
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should only allow setting of values for previously defined attributes" do
|
66
|
+
described_class.configure do |s|
|
67
|
+
s.fictional_feature_enabled = :off
|
68
|
+
end
|
69
|
+
|
70
|
+
described_class.fictional_feature_enabled.should == :off
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should only allow setting of values for previously defined attributes" do
|
74
|
+
lambda {
|
75
|
+
described_class.configure do |s|
|
76
|
+
s.undefined_setting = :should_raise_error
|
77
|
+
end
|
78
|
+
}.should raise_error
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "self.load_described_class" do
|
83
|
+
it "should load google analytics" do
|
84
|
+
Dir.should_receive(:glob).and_return(["config/described_class/some_service.yml"])
|
85
|
+
described_class.should_receive(:env).and_return("test")
|
86
|
+
YAML.should_receive(:load_file).and_return({"test" => "foo"})
|
87
|
+
described_class.load_settings
|
88
|
+
described_class.some_service.should == "foo"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
|
6
|
+
require "rspec/core"
|
7
|
+
require "rspec/mocks"
|
8
|
+
|
9
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.filter_run :focus
|
14
|
+
|
15
|
+
# Run specs in random order to surface order dependencies. If you find an
|
16
|
+
# order dependency and want to debug it, you can fix the order by providing
|
17
|
+
# the seed, which is printed after each run.
|
18
|
+
# --seed 1234
|
19
|
+
config.order = 'random'
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: figleaf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Juan C. Müller
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: activesupport
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: YAML based DRY settings manager.
|
63
|
+
email:
|
64
|
+
- jcmuller@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- figleaf.gemspec
|
76
|
+
- lib/figleaf.rb
|
77
|
+
- lib/figleaf/settings.rb
|
78
|
+
- lib/figleaf/version.rb
|
79
|
+
- spec/settings_spec.rb
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
homepage: http://github.com/challengepost/figleaf
|
82
|
+
licenses: []
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.8.24
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: YAML based DRY settings manager.
|
105
|
+
test_files:
|
106
|
+
- spec/settings_spec.rb
|
107
|
+
- spec/spec_helper.rb
|