couchbase-settings 0.0.4
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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +67 -0
- data/Rakefile +1 -0
- data/couchbase_settings.gemspec +33 -0
- data/lib/couchbase_settings/railtie.rb +10 -0
- data/lib/couchbase_settings/version.rb +3 -0
- data/lib/couchbase_settings.rb +46 -0
- metadata +57 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2012 Jasdeep Jaitla
|
|
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,67 @@
|
|
|
1
|
+
## CouchbaseSettings ##
|
|
2
|
+
|
|
3
|
+
Couchbase Server Settings in YAML for your Rails 3 app. Using patterns similar to the Yettings gem, it turns yaml into methods on the CouchbaseSettings module.
|
|
4
|
+
|
|
5
|
+
## Required: Rails 3 and Ruby >= 1.9.2-p271 ##
|
|
6
|
+
|
|
7
|
+
## Install the gem ##
|
|
8
|
+
|
|
9
|
+
Add this to your Gemfile
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem "couchbase-settings"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
Install with Bundler
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
$ bundle install
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Adding the YAML file with your key/value pairs ##
|
|
23
|
+
|
|
24
|
+
Create a YAML file inside /your_rails_app/config called couchbase.yml
|
|
25
|
+
|
|
26
|
+
## Couchbase YAML file content ##
|
|
27
|
+
|
|
28
|
+
You can define key/value pairs in the YAML file and these will be available in your app. You can set the defaults and any environment specific values.
|
|
29
|
+
The file must contain each environment that you will use in your Rails app. Here is a sample:
|
|
30
|
+
|
|
31
|
+
```yaml
|
|
32
|
+
defaults: &defaults
|
|
33
|
+
server: 127.0.0.1
|
|
34
|
+
servers:
|
|
35
|
+
- 127.0.0.1
|
|
36
|
+
- 127.0.0.2
|
|
37
|
+
|
|
38
|
+
bucket: default
|
|
39
|
+
password:
|
|
40
|
+
|
|
41
|
+
development:
|
|
42
|
+
<<: *defaults
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
test:
|
|
46
|
+
<<: *defaults
|
|
47
|
+
|
|
48
|
+
production:
|
|
49
|
+
<<: *defaults
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Accessing the values in your Rails app ##
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
# Single Server IP
|
|
56
|
+
CouchbaseSettings.server
|
|
57
|
+
|
|
58
|
+
# Server Cluster IP's (Array)
|
|
59
|
+
CouchbaseSettings.servers
|
|
60
|
+
|
|
61
|
+
# Server Bucket Name
|
|
62
|
+
CouchbaseSettings.bucket
|
|
63
|
+
|
|
64
|
+
# Bucket Password, if set
|
|
65
|
+
CouchbaseSettings.password
|
|
66
|
+
```
|
|
67
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'couchbase_settings/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |gem|
|
|
7
|
+
gem.name = "couchbase-settings"
|
|
8
|
+
gem.version = CouchbaseSettings::VERSION
|
|
9
|
+
gem.authors = ["Jasdeep Jaitla"]
|
|
10
|
+
gem.email = ["jasdeep@scalabl3.com"]
|
|
11
|
+
gem.description = %q{A Simple Couchbase Settings gem to read RAILS_ROOT/config/couchbase.yml file}
|
|
12
|
+
gem.summary = %q{A Simple Couchbase Settings gem to read RAILS_ROOT/config/couchbase.yml file}
|
|
13
|
+
gem.homepage = "https://github.com/scalabl3/couchbase-settings"
|
|
14
|
+
|
|
15
|
+
gem.extra_rdoc_files = [
|
|
16
|
+
"LICENSE.txt"
|
|
17
|
+
]
|
|
18
|
+
gem.files = [
|
|
19
|
+
"Gemfile",
|
|
20
|
+
"LICENSE.txt",
|
|
21
|
+
"README.md",
|
|
22
|
+
"Rakefile",
|
|
23
|
+
"VERSION",
|
|
24
|
+
"lib/couchbase_settings.rb",
|
|
25
|
+
"lib/couchbase_settings/railtie.rb",
|
|
26
|
+
"couchbase_settings.gemspec"
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
gem.files = `git ls-files`.split($/)
|
|
30
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
31
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
32
|
+
gem.require_paths = ["lib"]
|
|
33
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
require 'erb'
|
|
3
|
+
require "couchbase_settings/version"
|
|
4
|
+
|
|
5
|
+
COUCHBASE_PATH = "#{File.dirname(__FILE__)}/couchbase_settings"
|
|
6
|
+
puts COUCHBASE_PATH
|
|
7
|
+
require "#{COUCHBASE_PATH}/railtie.rb"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
module CouchbaseSettings
|
|
11
|
+
class UndefinedCouchbaseSettings < StandardError; end
|
|
12
|
+
class << self
|
|
13
|
+
def setup!
|
|
14
|
+
find_ymls.each do |yml|
|
|
15
|
+
create_cbsettings_class(yml)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def find_ymls
|
|
20
|
+
main_file = "#{Rails.root.to_s}/config/couchbase.yml"
|
|
21
|
+
couchbase_main_file = File.exists?(main_file) ? [main_file] : []
|
|
22
|
+
couchbase_namespaced_files = Dir.glob("#{Rails.root.to_s}/config/couchbase/**/*.yml")
|
|
23
|
+
couchbase_main_file.concat(couchbase_namespaced_files)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def create_cbsettings_class(yml_file)
|
|
27
|
+
hash = load_yml(yml_file)
|
|
28
|
+
klass_name = File.basename(yml_file).gsub(".yml","").camelize
|
|
29
|
+
klass_name = "#{klass_name}CouchbaseSettings" unless klass_name=="CouchbaseSettings"
|
|
30
|
+
klass = Object.const_set(klass_name,Class.new)
|
|
31
|
+
hash.each do |key,value|
|
|
32
|
+
klass.define_singleton_method(key){ value }
|
|
33
|
+
end
|
|
34
|
+
klass.class_eval do
|
|
35
|
+
def self.method_missing(method_id,*args)
|
|
36
|
+
raise UndefinedCouchbaseSettings, "#{method_id} is not defined in #{self.to_s}"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def load_yml(yml_file)
|
|
42
|
+
erb = ERB.new(File.read(yml_file)).result
|
|
43
|
+
erb.present? ? YAML.load(erb).to_hash[Rails.env] : {}
|
|
44
|
+
end
|
|
45
|
+
end # class << self
|
|
46
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: couchbase-settings
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.4
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Jasdeep Jaitla
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-10-31 00:00:00.000000000 Z
|
|
13
|
+
dependencies: []
|
|
14
|
+
description: A Simple Couchbase Settings gem to read RAILS_ROOT/config/couchbase.yml
|
|
15
|
+
file
|
|
16
|
+
email:
|
|
17
|
+
- jasdeep@scalabl3.com
|
|
18
|
+
executables: []
|
|
19
|
+
extensions: []
|
|
20
|
+
extra_rdoc_files:
|
|
21
|
+
- LICENSE.txt
|
|
22
|
+
files:
|
|
23
|
+
- .gitignore
|
|
24
|
+
- Gemfile
|
|
25
|
+
- LICENSE.txt
|
|
26
|
+
- README.md
|
|
27
|
+
- Rakefile
|
|
28
|
+
- couchbase_settings.gemspec
|
|
29
|
+
- lib/couchbase_settings.rb
|
|
30
|
+
- lib/couchbase_settings/railtie.rb
|
|
31
|
+
- lib/couchbase_settings/version.rb
|
|
32
|
+
homepage: https://github.com/scalabl3/couchbase-settings
|
|
33
|
+
licenses: []
|
|
34
|
+
post_install_message:
|
|
35
|
+
rdoc_options: []
|
|
36
|
+
require_paths:
|
|
37
|
+
- lib
|
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
39
|
+
none: false
|
|
40
|
+
requirements:
|
|
41
|
+
- - ! '>='
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
|
+
none: false
|
|
46
|
+
requirements:
|
|
47
|
+
- - ! '>='
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '0'
|
|
50
|
+
requirements: []
|
|
51
|
+
rubyforge_project:
|
|
52
|
+
rubygems_version: 1.8.24
|
|
53
|
+
signing_key:
|
|
54
|
+
specification_version: 3
|
|
55
|
+
summary: A Simple Couchbase Settings gem to read RAILS_ROOT/config/couchbase.yml file
|
|
56
|
+
test_files: []
|
|
57
|
+
has_rdoc:
|