app_settings 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/Rakefile +11 -0
- data/app_settings.gemspec +22 -0
- data/bin/bundler +16 -0
- data/bin/erubis +16 -0
- data/bin/rackup +16 -0
- data/bin/rails +16 -0
- data/bin/rake +16 -0
- data/bin/sprockets +16 -0
- data/bin/thor +16 -0
- data/bin/tilt +16 -0
- data/bin/tt +16 -0
- data/lib/app_settings/railtie.rb +23 -0
- data/lib/app_settings.rb +1 -0
- data/test/railtie_test.rb +64 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cdb19c79acaec9be18c3b1392a88780e41f030bc
|
4
|
+
data.tar.gz: 9e9aa6e9e0a2b14cbb761652becd75e69342233f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cf688753ab7ea276480b1936d0d330f3c977f9dbb8159e3d69ab4014ba039b053756dcfc755f06962daef7f67303a93c995d72c371ff52766cbdc97668dc3039
|
7
|
+
data.tar.gz: f491d3059868a836a50cc338e410c8839aa146605275b532779d14426d9e05709719df68f154aa5d6a63c0f98a2d7e38b973f5738c8a8df7a2de6eeeed577662
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Robert Evans
|
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,60 @@
|
|
1
|
+
# App Settings
|
2
|
+
|
3
|
+
**Application-wide Settings for Rails**
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/revans/app_settings.png)](https://travis-ci.org/revans/app_settings)
|
6
|
+
|
7
|
+
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/revans/app_settings)
|
8
|
+
|
9
|
+
|
10
|
+
Sometimes there is a need to have values stored that can be used
|
11
|
+
anywhere inside a Rails application. Things like the application name,
|
12
|
+
or the company name, etc. are simple use cases. Other times you might
|
13
|
+
want to add oauth key/secret for twitter/facebook.
|
14
|
+
|
15
|
+
There are numerous ways in which you can handle that:
|
16
|
+
|
17
|
+
* put it into a initializer
|
18
|
+
* create a custom object, maybe subclassing OpenStruct/Struct
|
19
|
+
* a Yaml file that you'll load/parse in an initializer file
|
20
|
+
* and many other ways
|
21
|
+
|
22
|
+
I've been doing a mix of initializers and a custom object, but
|
23
|
+
never been fully happy with those solutions. Rails already has
|
24
|
+
a place for configuration settings for the application, so it
|
25
|
+
made sense to me, to use that.
|
26
|
+
|
27
|
+
This tiny gem does just that. Here's how you can do it too:
|
28
|
+
|
29
|
+
|
30
|
+
In your Gemfile, include this gem:
|
31
|
+
|
32
|
+
````
|
33
|
+
gem 'app_settings'
|
34
|
+
````
|
35
|
+
|
36
|
+
|
37
|
+
You can choose to have specific environment settings, but using
|
38
|
+
the config/environments/*.rb files, or put it into the config/application.rb
|
39
|
+
file. Your choice.
|
40
|
+
|
41
|
+
inside one of those files:
|
42
|
+
|
43
|
+
````
|
44
|
+
config.app_settings.appname = 'My Rails Application'
|
45
|
+
config.app_settings.company_name = 'Fancy Pants LLC'
|
46
|
+
````
|
47
|
+
|
48
|
+
Then, anywhere in your app, you can access those by doing:
|
49
|
+
|
50
|
+
````
|
51
|
+
Rails.application.config.app_settings.appname # => 'My Rails Application'
|
52
|
+
Rails.application.config.app_settings.company_name # => 'Fancy Pants LLC'
|
53
|
+
````
|
54
|
+
|
55
|
+
From there, you could put those into the app/controllers/application_controller.rb
|
56
|
+
file and shorten the name and then make it also a helper method. You could also
|
57
|
+
put it into your models as a method or use [Rails'
|
58
|
+
config_accessor](http://api.rubyonrails.org/classes/ActiveSupport/Configurable/ClassMethods.html#method-i-config_accessor). You'll get the benefit of having your app settings all in one place.
|
59
|
+
|
60
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "app_settings"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["Robert Evans"]
|
9
|
+
spec.email = ["robert@codewranglers.org"]
|
10
|
+
spec.summary = %q{Application wide settings}
|
11
|
+
spec.description = %q{Application wide settings}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
data/bin/bundler
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'bundler' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('bundler', 'bundler')
|
data/bin/erubis
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'erubis' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('erubis', 'erubis')
|
data/bin/rackup
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rackup' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rack', 'rackup')
|
data/bin/rails
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rails' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('railties', 'rails')
|
data/bin/rake
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rake' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rake', 'rake')
|
data/bin/sprockets
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'sprockets' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('sprockets', 'sprockets')
|
data/bin/thor
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'thor' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('thor', 'thor')
|
data/bin/tilt
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'tilt' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('tilt', 'tilt')
|
data/bin/tt
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'tt' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('treetop', 'tt')
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'active_support/core_ext/module/remove_method'
|
3
|
+
|
4
|
+
module Rails
|
5
|
+
class Application
|
6
|
+
|
7
|
+
class Configuration
|
8
|
+
remove_possible_method :settings
|
9
|
+
end
|
10
|
+
|
11
|
+
# Undefine settings, if it even exists
|
12
|
+
remove_possible_method :settings
|
13
|
+
remove_possible_method :settings=
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
module AppSettings
|
20
|
+
class Railtie < Rails::Railtie
|
21
|
+
config.settings = ActiveSupport::OrderedOptions.new
|
22
|
+
end
|
23
|
+
end
|
data/lib/app_settings.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'app_settings/railtie' if defined? Rails
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest/pride'
|
3
|
+
|
4
|
+
require 'active_support'
|
5
|
+
require 'active_support/testing/isolation'
|
6
|
+
require 'pathname'
|
7
|
+
|
8
|
+
class TestBoot < Minitest::Test
|
9
|
+
include ::ActiveSupport::Testing::Isolation
|
10
|
+
|
11
|
+
ROOT = File.expand_path("../../tmp/app", __FILE__)
|
12
|
+
|
13
|
+
attr_reader :app
|
14
|
+
|
15
|
+
def setup
|
16
|
+
require 'rails'
|
17
|
+
|
18
|
+
require 'active_support/dependencies'
|
19
|
+
require 'tzinfo'
|
20
|
+
|
21
|
+
ENV['RAILS_ENV'] = 'test'
|
22
|
+
|
23
|
+
FileUtils.mkdir_p ROOT
|
24
|
+
Dir.chdir ROOT
|
25
|
+
|
26
|
+
@app = Class.new(Rails::Application)
|
27
|
+
|
28
|
+
# Get bitched at if you don't set these
|
29
|
+
@app.config.eager_load = false
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_initialize
|
34
|
+
app.initialize!
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class TestRailtie < TestBoot
|
39
|
+
|
40
|
+
def setup
|
41
|
+
require ::Pathname.new(__dir__).join('../lib/app_settings/railtie').to_s
|
42
|
+
super
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def test_defaults
|
47
|
+
app.initialize!
|
48
|
+
|
49
|
+
assert_empty app.config.settings
|
50
|
+
assert_instance_of ActiveSupport::OrderedOptions, app.config.settings
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def test_storing_info_in_settings
|
55
|
+
assert_empty app.config.settings
|
56
|
+
app.config.settings.app_name = 'Test Name'
|
57
|
+
|
58
|
+
app.initialize!
|
59
|
+
|
60
|
+
refute_empty app.config.settings
|
61
|
+
assert_equal 'Test Name', app.config.settings.app_name
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: app_settings
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Evans
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Application wide settings
|
42
|
+
email:
|
43
|
+
- robert@codewranglers.org
|
44
|
+
executables:
|
45
|
+
- bundler
|
46
|
+
- erubis
|
47
|
+
- rackup
|
48
|
+
- rails
|
49
|
+
- rake
|
50
|
+
- sprockets
|
51
|
+
- thor
|
52
|
+
- tilt
|
53
|
+
- tt
|
54
|
+
extensions: []
|
55
|
+
extra_rdoc_files: []
|
56
|
+
files:
|
57
|
+
- ".gitignore"
|
58
|
+
- ".travis.yml"
|
59
|
+
- Gemfile
|
60
|
+
- LICENSE.txt
|
61
|
+
- README.md
|
62
|
+
- Rakefile
|
63
|
+
- app_settings.gemspec
|
64
|
+
- bin/bundler
|
65
|
+
- bin/erubis
|
66
|
+
- bin/rackup
|
67
|
+
- bin/rails
|
68
|
+
- bin/rake
|
69
|
+
- bin/sprockets
|
70
|
+
- bin/thor
|
71
|
+
- bin/tilt
|
72
|
+
- bin/tt
|
73
|
+
- lib/app_settings.rb
|
74
|
+
- lib/app_settings/railtie.rb
|
75
|
+
- test/railtie_test.rb
|
76
|
+
homepage: ''
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.2.2
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Application wide settings
|
100
|
+
test_files:
|
101
|
+
- test/railtie_test.rb
|