sm_app_config 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dca19cd9859e9a5e67c278060c8dc663b1bf6b3b
4
+ data.tar.gz: 3f9fedd786e4ddb981619ea3dfe1e23d73f8bd89
5
+ SHA512:
6
+ metadata.gz: fcee7f4e9079a81f7c534eaf0395f5ee77dfec3a47c0e6ce1450cd844a85cf8339bdca68abfbff3e379bf55274efc83a9b25db353ff97557e455c0ac809e87fb
7
+ data.tar.gz: fe5266fd5d9fcef88297db06ebc7808f12f657bd1809a0cc78015429dcb8647ac30da1f0526c3ca44fc54caa5a575271f327abc60c3aa9c7524cf994e2bfaa70
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .ruby-version
11
+ .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sm_app_config.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jack Whitis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # SmAppConfig
2
+
3
+ SmAppConfig (Southern Made App Config) is a framework agnostic library for storing and retrieving configuration settings using a YAML file or ENV variables. SmAppConfig will look first for an ENV variable with the specified name, then fall back to the YAML file if one is not found. Configuration files are excluded from source control by default. See below for usage instructions.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'sm_app_config'
11
+ ```
12
+
13
+ And then run:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install sm_app_config
20
+
21
+ Run the generator to create configuration files:
22
+
23
+ $ app_config install
24
+
25
+ Or with --no-rails if your app does not use Rails:
26
+
27
+ $ app_congfig install --no-rails
28
+
29
+ This will do the following:
30
+
31
+ - Create a configuration file at `config/app_config.yml`
32
+ - Create an example configuration file at `config/app_config.example.yml`
33
+ - Add `config/app_config.yml` to your `.gitignore` file
34
+
35
+ ## Usage
36
+
37
+ To add configuration settings, simply add key/value pairs to `app_config.yml`, which is located in `config/` by default. If you are using Rails, you should place them under each applicable environment namespace. You should also add the keys with placeholder values to `app_config.example.yml`. This file should be checked into source control so that other developers know what keys need to be present in `app_config.yml`.
38
+
39
+ You also have the option to store your configuration settings in ENV variables. This would be the desired approach if you were deploying to Heroku. Regardless of how your settings are stored, they can be accessed in this way:
40
+
41
+ ```ruby
42
+ AppConfig['my-setting']
43
+ ```
44
+
45
+ If an ENV variable named MY-SETTING is not found, SmAppConfig will look in `app_config.yml` for a key named my-setting. If you are using Rails, it will look for the key under the appropriate environment namespace. An error will be raised if the setting is not found or if `app_config.yml` does not exist.
46
+
47
+ If you change `app_config.yml`, be sure to run:
48
+
49
+ ```ruby
50
+ AppConfig.reload!
51
+ ```
52
+
53
+ You can customize the name and location of your configuration file:
54
+
55
+ ```ruby
56
+ SmAppConfig.configure(path: "custom/app_config.yml")
57
+ ```
58
+
59
+ ## Development
60
+
61
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
62
+
63
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sm_app_config. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
68
+
69
+
70
+ ## License
71
+
72
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
73
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sm_app_config"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ sample_basic_setting: my-setting
2
+ very_false: false
3
+ test:
4
+ rails_setting: true
data/exe/app_config ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "thor"
4
+ require_relative "../lib/generators/sm_app_config/install_generator"
5
+
6
+ SmAppConfig::InstallGenerator.start
@@ -0,0 +1,42 @@
1
+ module SmAppConfig
2
+ class InstallGenerator < Thor
3
+ include Thor::Actions
4
+
5
+ def self.source_root
6
+ File.expand_path("../../templates", __FILE__)
7
+ end
8
+
9
+ desc "install", "Copies configuration files to config/"
10
+ method_options rails: true, desc: "Add Rails environments to configuration files"
11
+ def install
12
+ copy_app_config
13
+ copy_app_config_example
14
+ add_app_config_to_gitignore
15
+ end
16
+
17
+ desc "copy_app_config", "Copies app_config.yml to config/"
18
+ def copy_app_config
19
+ copy_file config_template, "config/app_config.yml"
20
+ say "Copied app_config.yml to config/"
21
+ end
22
+
23
+ desc "copy_app_config_example", "Copies app_config.example.yml to config/"
24
+ def copy_app_config_example
25
+ copy_file config_template, "config/app_config.example.yml"
26
+ say "Copied app_config.example.yml to config/"
27
+ end
28
+
29
+ desc "add_app_config_to_gitignore", "Adds app_config.yml to .gitignore"
30
+ def add_app_config_to_gitignore
31
+ append_to_file ".gitignore", "\n/config/app_config.yml"
32
+ say "Added /config/app_config.yml to .gitignore"
33
+ end
34
+
35
+ private
36
+
37
+ def config_template
38
+ @template ||= options[:rails] ? "rails_app_config.yml" : "app_config.yml"
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1 @@
1
+ foo: bar
@@ -0,0 +1,6 @@
1
+ development:
2
+ foo: "bar"
3
+ production:
4
+ foo: "bar"
5
+ test:
6
+ foo: "bar"
@@ -0,0 +1,40 @@
1
+ require 'yaml'
2
+
3
+ class AppConfig
4
+
5
+ def self.[] key
6
+ result = ENV[key.upcase]
7
+ return YAML.load(result) unless result.nil?
8
+
9
+ result = config[key]
10
+ return result unless result.nil?
11
+
12
+ raise ArgumentError.new("No ENV['#{key.upcase}'] or AppConfig['#{key}'] setting found")
13
+ end
14
+
15
+ def self.reload!
16
+ @config = nil
17
+ end
18
+
19
+ private
20
+
21
+ def self.config
22
+ @config ||= begin
23
+ raw_config = File.read(config_file)
24
+ loaded = YAML.load(raw_config)
25
+
26
+ if defined?(Rails)
27
+ loaded[Rails.env] or raise "No configuration found for environment #{Rails.env}"
28
+ else
29
+ loaded
30
+ end
31
+ rescue SystemCallError
32
+ raise "No configuration file found at #{config_file}"
33
+ end
34
+ end
35
+
36
+ def self.config_file
37
+ SmAppConfig::CONFIG.fetch(:path)
38
+ end
39
+
40
+ end
@@ -0,0 +1,25 @@
1
+ require 'forwardable'
2
+
3
+ module SmAppConfig
4
+ class Configuration
5
+ extend Forwardable
6
+ def_delegators :@hash, :to_hash, :[], :[]=, :==, :fetch, :delete
7
+
8
+ DEFAULTS = {
9
+ path: "config/app_config.yml"
10
+ }
11
+
12
+ def initialize
13
+ clear
14
+ end
15
+
16
+ def clear
17
+ @hash = DEFAULTS.dup
18
+ end
19
+
20
+ def merge! configuration_hash
21
+ @hash.merge!(configuration_hash)
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module SmAppConfig
2
+ VERSION = "0.2.2"
3
+ end
@@ -0,0 +1,18 @@
1
+ require "sm_app_config/version"
2
+ require "sm_app_config/configuration"
3
+ require "sm_app_config/app_config"
4
+
5
+ module SmAppConfig
6
+ extend self
7
+
8
+ CONFIG = Configuration.new
9
+
10
+ def configure configuration_options = {}
11
+ CONFIG.merge!(configuration_options)
12
+ end
13
+
14
+ def clear!
15
+ CONFIG.clear
16
+ end
17
+
18
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sm_app_config/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sm_app_config"
8
+ spec.version = SmAppConfig::VERSION
9
+ spec.authors = ["Jack Whitis", "Matt Mueller"]
10
+ spec.email = ["jack@southernmade.co"]
11
+
12
+ spec.summary = %q{Application configuration for multiple environments.}
13
+ spec.description = %q{Library for managing application configuration using a YAML file or ENV variables.}
14
+ spec.homepage = "https://github.com/SouthernMade/sm_app_config"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.post_install_message = "Run `app_config install` to complete installation."
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+
28
+ spec.add_runtime_dependency "thor"
29
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sm_app_config
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Jack Whitis
8
+ - Matt Mueller
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2015-07-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.10'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.10'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: thor
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description: Library for managing application configuration using a YAML file or ENV
71
+ variables.
72
+ email:
73
+ - jack@southernmade.co
74
+ executables:
75
+ - app_config
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - config/app_config.yml
89
+ - exe/app_config
90
+ - lib/generators/sm_app_config/install_generator.rb
91
+ - lib/generators/templates/app_config.yml
92
+ - lib/generators/templates/rails_app_config.yml
93
+ - lib/sm_app_config.rb
94
+ - lib/sm_app_config/app_config.rb
95
+ - lib/sm_app_config/configuration.rb
96
+ - lib/sm_app_config/version.rb
97
+ - sm_app_config.gemspec
98
+ homepage: https://github.com/SouthernMade/sm_app_config
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message: Run `app_config install` to complete installation.
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.4.6
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Application configuration for multiple environments.
122
+ test_files: []