kredentials 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kredentials.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Bookrenter/Rafter
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,51 @@
1
+ # Kredentials
2
+
3
+ Gem allows to define config constants for different Rails environments.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'kredentials'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install kredentials
18
+
19
+ ## Usage
20
+
21
+ class HostConfig
22
+ extend Credentials
23
+
24
+ @@development = {
25
+ :my_host => 'www.local.myhost.com',
26
+ :my_subdomain => 'www.local',
27
+ }
28
+
29
+ @@test = {
30
+ :my_host => 'mobi.test.myhost.com',
31
+ :my_subdomain => 'mobi.test',
32
+ }
33
+
34
+ @@production = {
35
+ :my_host => 'www.myhost.com',
36
+ :my_subdomain => 'www',
37
+ }
38
+ end
39
+
40
+
41
+ HostConfig.my_host # will return my_host based on the Rails environment you are in
42
+
43
+ # Credits
44
+
45
+ [Oha_extensions](https://github.com/bkr/oha_extensions) is maintained by [Bookrenter/Rafter](http://github.com/bkr) and is funded by [BookRenter.com](http://www.bookrenter.com "BookRenter.com").
46
+
47
+ ![BookRenter.com Logo](http://assets0.bookrenter.com/images/header/bookrenter_logo.gif "BookRenter.com")
48
+
49
+ # Copyright
50
+
51
+ Copyright (c) 2012 Bookrenter.com. See LICENSE.txt for further details.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task default: :spec
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/kredentials/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Bookrenter/Rafter"]
6
+ gem.email = ["cp@bookrenter.com"]
7
+ gem.description = %q{Gem allows to define config constants for different Rails environments.}
8
+ gem.summary = %q{Gem allows to define config constants for different Rails environments.}
9
+ gem.homepage = "https://github.com/bkr/kredentials"
10
+
11
+ gem.add_development_dependency 'rspec'
12
+ gem.add_development_dependency 'supermodel'
13
+
14
+ gem.files = `git ls-files`.split($\)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.name = "kredentials"
18
+ gem.require_paths = ["lib"]
19
+ gem.version = Kredentials::VERSION
20
+ end
@@ -0,0 +1,3 @@
1
+ require "kredentials/version"
2
+ require "kredentials/credentials"
3
+
@@ -0,0 +1,37 @@
1
+ module Credentials
2
+
3
+ def self.extended(cls)
4
+ cls.cattr_accessor(:config_env)
5
+ cls.config_env = nil
6
+ end
7
+
8
+ %W[production development test staging].each do |environment|
9
+ self.send(:define_method, "#{environment}") do
10
+ self.class_variable_defined?("@@#{environment}") ? class_eval("@@#{environment}") : {}
11
+ end
12
+ end
13
+
14
+ self.send(:define_method, :to_hash) do
15
+ hash = self.class_variable_defined?('@@defaults') ? self.class_eval("@@defaults").clone : {}
16
+ env = self.config_env || Rails.env
17
+ hash.merge!(self.class_eval("@@#{env}")) if self.class_variable_defined?("@@#{env}")
18
+ HashWithIndifferentAccess.new(hash)
19
+ end
20
+
21
+ def method_missing(method)
22
+ value =
23
+ case self.config_env || Rails.env
24
+ when 'production'
25
+ self.production[method.to_sym]
26
+ when 'staging'
27
+ self.staging[method.to_sym] || self.development[method.to_sym]
28
+ when 'test'
29
+ self.test[method.to_sym]
30
+ else
31
+ self.development[method.to_sym]
32
+ end
33
+ return value || (self.class_variable_defined?('@@defaults') ?
34
+ self.class_eval("@@defaults")[method.to_sym] : nil)
35
+ end
36
+
37
+ end
@@ -0,0 +1,3 @@
1
+ module Kredentials
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,131 @@
1
+ require 'spec_helper'
2
+
3
+ class TestConfig
4
+ extend Credentials
5
+ @@test = {:key => 'test'}
6
+ end
7
+
8
+ class TestDefaultConfig
9
+ extend Credentials
10
+ @@defaults = {:key => 'default'}
11
+ @@production = {:key => 'production'}
12
+ @@staging = {:key => 'staging'}
13
+ end
14
+
15
+ class TestNoStagingConfig
16
+ extend Credentials
17
+ @@development = {:key => 'development'}
18
+ @@production = {:key => 'production'}
19
+ end
20
+
21
+ describe "kredentials" do
22
+ describe "test" do
23
+ before do
24
+ if !defined?(Rails)
25
+ class Rails
26
+ end
27
+ Rails.stub(:env).and_return("test")
28
+ end
29
+ end
30
+
31
+ it "should have test key" do
32
+ TestConfig.key.should == "test"
33
+ end
34
+ end
35
+
36
+ describe "default credentials for staging w/o defaults set or staging set" do
37
+ before do
38
+ TestNoStagingConfig.config_env = 'staging'
39
+ end
40
+
41
+ it "should have development key" do
42
+ TestNoStagingConfig.key.should == "development"
43
+ end
44
+ end
45
+
46
+ describe "default credentials" do
47
+
48
+ describe "production" do
49
+ before do
50
+ TestDefaultConfig.config_env = 'production'
51
+ end
52
+
53
+ it "should be production" do
54
+ TestDefaultConfig.key.should == 'production'
55
+ end
56
+ end
57
+
58
+ describe "staging" do
59
+ before do
60
+ TestDefaultConfig.config_env = 'staging'
61
+ end
62
+
63
+ it "should be staging" do
64
+ TestDefaultConfig.key.should == 'staging'
65
+ end
66
+ end
67
+
68
+ describe "test" do
69
+ before do
70
+ TestDefaultConfig.config_env = 'test'
71
+ end
72
+
73
+ it "should be default" do
74
+ TestDefaultConfig.key.should == 'default'
75
+ end
76
+ end
77
+
78
+ describe "development" do
79
+ before do
80
+ TestDefaultConfig.config_env = 'development'
81
+ end
82
+
83
+ it "should be development" do
84
+ TestDefaultConfig.key.should == 'default'
85
+ end
86
+ end
87
+ end
88
+
89
+ describe "test to hash" do
90
+ describe "production" do
91
+ before do
92
+ TestDefaultConfig.config_env = 'production'
93
+ end
94
+
95
+ it "should be production" do
96
+ TestDefaultConfig.to_hash['key'].should == 'production'
97
+ TestDefaultConfig.to_hash[:key].should == 'production'
98
+ end
99
+ end
100
+ describe "staging" do
101
+ before do
102
+ TestDefaultConfig.config_env = 'staging'
103
+ end
104
+
105
+ it "should be production" do
106
+ TestDefaultConfig.to_hash['key'].should == 'staging'
107
+ TestDefaultConfig.to_hash[:key].should == 'staging'
108
+ end
109
+ end
110
+ describe "test" do
111
+ before do
112
+ TestDefaultConfig.config_env = 'test'
113
+ end
114
+
115
+ it "should be production" do
116
+ TestDefaultConfig.to_hash['key'].should == 'default'
117
+ TestDefaultConfig.to_hash[:key].should == 'default'
118
+ end
119
+ end
120
+ describe "development" do
121
+ before do
122
+ TestDefaultConfig.config_env = 'development'
123
+ end
124
+
125
+ it "should be production" do
126
+ TestDefaultConfig.to_hash['key'].should == 'default'
127
+ TestDefaultConfig.to_hash[:key].should == 'default'
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,2 @@
1
+ require 'kredentials'
2
+ require 'supermodel'
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kredentials
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bookrenter/Rafter
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
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: supermodel
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
+ description: Gem allows to define config constants for different Rails environments.
47
+ email:
48
+ - cp@bookrenter.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - .rspec
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - kredentials.gemspec
60
+ - lib/kredentials.rb
61
+ - lib/kredentials/credentials.rb
62
+ - lib/kredentials/version.rb
63
+ - spec/kredentials/credentials_spec.rb
64
+ - spec/spec_helper.rb
65
+ homepage: https://github.com/bkr/kredentials
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.24
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Gem allows to define config constants for different Rails environments.
89
+ test_files:
90
+ - spec/kredentials/credentials_spec.rb
91
+ - spec/spec_helper.rb