configvars_rails 0.2.1 → 0.2.2
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/README.rdoc +12 -3
- data/VERSION +1 -1
- data/configvars_rails.gemspec +2 -2
- data/lib/configvars_rails/controller.rb +3 -4
- data/lib/configvars_rails/generators/templates/config_vars_controller.rb +3 -3
- data/lib/configvars_rails/generators/templates/config_vars_initializer.rb +7 -3
- data/test/config_vars_controller_api_test.rb +6 -5
- data/test/descriptor_test.rb +5 -6
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -28,14 +28,23 @@ Configuration variables are defined as follows:
|
|
28
28
|
ConfigVars.string :variable_name, 'default value'
|
29
29
|
ConfigVars.string(:variable_name) { 'block producing default value' }
|
30
30
|
|
31
|
-
It is safe to define configuration variables
|
32
|
-
|
33
|
-
|
31
|
+
It is safe to define configuration variables anywhere in your code - make sure
|
32
|
+
it gets loaded in development mode, though! The scaffold defines a couple
|
33
|
+
variables in config/initializers/config_vars.rb
|
34
|
+
|
35
|
+
Variables can be redefined. Other plugins can define their own variables, as
|
36
|
+
long as they include configvars_rails as a gem dependency, to ensure proper load
|
37
|
+
order.
|
34
38
|
|
35
39
|
When the application is running, a rudimentary UI for editing configuration
|
36
40
|
variables is available at
|
37
41
|
http://your-app-server/config_vars
|
38
42
|
|
43
|
+
By default, the page is protected with HTTP Basic authentication. The default
|
44
|
+
username:password combo is config:vars. The credentials can be tweaked by
|
45
|
+
(you guessed!) changing the config_vars.http_user and config_vars.http_password
|
46
|
+
configuration variables.
|
47
|
+
|
39
48
|
== Note on Patches/Pull Requests
|
40
49
|
|
41
50
|
* Fork the project.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/configvars_rails.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{configvars_rails}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Victor Costan"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-10}
|
13
13
|
s.description = %q{This gem provides a model and simple controller for
|
14
14
|
storing global application configuration in a database. This allows the
|
15
15
|
configuration to change without source code modifications.}
|
@@ -34,10 +34,9 @@ module ControllerInstanceMethods
|
|
34
34
|
|
35
35
|
defined_names = ConfigvarsRails.variable_names
|
36
36
|
default_names = defined_names - @config_vars.map { |var| var.name.to_sym }
|
37
|
-
@default_vars = {
|
38
|
-
|
39
|
-
|
40
|
-
end
|
37
|
+
@default_vars = default_names.map { |name|
|
38
|
+
[name.to_s, ConfigvarsRails.variable_descriptor(name)]
|
39
|
+
}.sort
|
41
40
|
|
42
41
|
respond_to do |format|
|
43
42
|
format.html # index.html.erb
|
@@ -3,12 +3,12 @@ class ConfigVarsController < ApplicationController
|
|
3
3
|
config_vars_controller
|
4
4
|
|
5
5
|
# Configuration variables are usually sensitive, so let's put some protection
|
6
|
-
# around modifying them.
|
7
|
-
USER, PASSWORD = 'config', 'vars'
|
6
|
+
# around modifying them.
|
8
7
|
before_filter :http_basic_check
|
9
8
|
def http_basic_check
|
10
9
|
authenticate_or_request_with_http_basic do |user, password|
|
11
|
-
user ==
|
10
|
+
user == ConfigVar['config_vars.http_user'] &&
|
11
|
+
password == ConfigVar['config_vars.http_password']
|
12
12
|
end
|
13
13
|
end
|
14
14
|
private :http_basic_check
|
@@ -1,4 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# Used in the scaffolded ConfigVarsController.
|
2
|
+
ConfigVars.string 'config_vars.http_user', 'config'
|
3
|
+
ConfigVars.string 'config_vars.http_password', 'vars'
|
2
4
|
|
3
|
-
|
4
|
-
ConfigVars.string('
|
5
|
+
# Example use only. Remove after reading.
|
6
|
+
ConfigVars.string('block_example') { Time.now }
|
7
|
+
|
8
|
+
# Define your own configuration variables here.
|
@@ -20,8 +20,9 @@ class ConfigVarsControllerApiTest < ActionController::TestCase
|
|
20
20
|
|
21
21
|
assert assigns(:config_vars).include?(config_vars(:app_uri)),
|
22
22
|
"@config_vars doesn't have a database fixture"
|
23
|
-
assert assigns(:default_vars).
|
24
|
-
|
23
|
+
assert assigns(:default_vars).map(&:first).
|
24
|
+
include?('config_vars.http_user'),
|
25
|
+
"@default_vars doesn't have config_vars:http_user"
|
25
26
|
end
|
26
27
|
|
27
28
|
test "should get new" do
|
@@ -36,10 +37,10 @@ class ConfigVarsControllerApiTest < ActionController::TestCase
|
|
36
37
|
end
|
37
38
|
|
38
39
|
test "new with preset name and default value" do
|
39
|
-
get :new, :name => '
|
40
|
+
get :new, :name => 'config_vars.http_user'
|
40
41
|
assert_response :success
|
41
|
-
assert_equal '
|
42
|
-
assert_equal '
|
42
|
+
assert_equal 'config_vars.http_user', assigns(:config_var).name
|
43
|
+
assert_equal 'config', assigns(:config_var).value
|
43
44
|
end
|
44
45
|
|
45
46
|
test "should create config_var" do
|
data/test/descriptor_test.rb
CHANGED
@@ -2,14 +2,13 @@ require File.expand_path('../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
class DescriptorTest < ActiveSupport::TestCase
|
4
4
|
setup do
|
5
|
-
@simple_desc = ConfigvarsRails.variable_descriptor '
|
6
|
-
@block_desc = ConfigvarsRails.variable_descriptor '
|
5
|
+
@simple_desc = ConfigvarsRails.variable_descriptor 'config_vars.http_user'
|
6
|
+
@block_desc = ConfigvarsRails.variable_descriptor 'block_example'
|
7
7
|
end
|
8
8
|
|
9
9
|
test 'default_value' do
|
10
|
-
assert_equal '
|
11
|
-
assert_in_delta Time.now, @block_desc.default_value, 0.1
|
12
|
-
'first block call'
|
10
|
+
assert_equal 'config', @simple_desc.default_value
|
11
|
+
assert_in_delta Time.now, @block_desc.default_value, 0.1
|
13
12
|
end
|
14
13
|
|
15
14
|
test 'value_type' do
|
@@ -17,6 +16,6 @@ class DescriptorTest < ActiveSupport::TestCase
|
|
17
16
|
end
|
18
17
|
|
19
18
|
test 'default_value fallback in ConfigVar[]' do
|
20
|
-
assert_equal '
|
19
|
+
assert_equal 'config', ConfigVar['config_vars.http_user']
|
21
20
|
end
|
22
21
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configvars_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Victor Costan
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-10 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|