configvars_rails 0.4.5 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/configvars_rails.gemspec +3 -2
- data/lib/configvars_rails/auth.rb +27 -0
- data/lib/configvars_rails/controller.rb +71 -103
- data/lib/configvars_rails/generators/templates/config_var.rb +1 -1
- data/lib/configvars_rails/generators/templates/config_vars_controller.rb +1 -1
- data/lib/configvars_rails/model.rb +37 -54
- data/lib/configvars_rails.rb +1 -0
- metadata +5 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
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.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{Victor Costan}]
|
12
|
-
s.date = %q{2011-06
|
12
|
+
s.date = %q{2011-07-06}
|
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.}
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"app/helpers/config_vars_helper.rb",
|
30
30
|
"configvars_rails.gemspec",
|
31
31
|
"lib/configvars_rails.rb",
|
32
|
+
"lib/configvars_rails/auth.rb",
|
32
33
|
"lib/configvars_rails/controller.rb",
|
33
34
|
"lib/configvars_rails/descriptor.rb",
|
34
35
|
"lib/configvars_rails/engine.rb",
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'action_controller'
|
2
|
+
|
3
|
+
# :nodoc: add config_vars_auth ro ActiveController class methods
|
4
|
+
class ActionController::Base
|
5
|
+
# HTTP Basic for controller actions, using config_vars credentials.
|
6
|
+
def self.config_vars_auth(*args)
|
7
|
+
include ConfigvarsRails::AuthInstanceMethods
|
8
|
+
before_filter :config_vars_http_basic_check, *args
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# :nodoc: namespace
|
13
|
+
module ConfigvarsRails
|
14
|
+
|
15
|
+
# Included in controllers that call config_vars_controller.
|
16
|
+
module AuthInstanceMethods
|
17
|
+
def config_vars_http_basic_check
|
18
|
+
authenticate_or_request_with_http_basic(
|
19
|
+
ConfigVar['config_vars.http_realm']) do |user, password|
|
20
|
+
user == ConfigVar['config_vars.http_user'] &&
|
21
|
+
password == ConfigVar['config_vars.http_password']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
private :config_vars_http_basic_check
|
25
|
+
end # module ConfigvarsRails::AuthInstanceMethods
|
26
|
+
|
27
|
+
end # namespace ConfigvarsRails
|
@@ -1,121 +1,89 @@
|
|
1
|
-
require '
|
1
|
+
require 'active_support'
|
2
2
|
|
3
3
|
# :nodoc: namespace
|
4
4
|
module ConfigvarsRails
|
5
5
|
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
module
|
11
|
-
|
12
|
-
base.send :extend, ControllerClassMethods
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# Methods here become ActiveController::Base class methods.
|
17
|
-
module ControllerClassMethods
|
6
|
+
# Included by the config vars management controller.
|
7
|
+
#
|
8
|
+
# Some parts of the codebase expect the controller to be named
|
9
|
+
# ConfigVarsController.
|
10
|
+
module Controller
|
11
|
+
extend ActiveSupport::Concern
|
18
12
|
|
19
|
-
|
20
|
-
#
|
21
|
-
# Right now, this should be called from ConfigVarsController. The controller
|
22
|
-
# name is hardwired in other parts of the implementation.
|
23
|
-
def config_vars_controller
|
24
|
-
include ControllerInstanceMethods
|
13
|
+
included do
|
25
14
|
layout 'config_vars'
|
26
15
|
end
|
27
|
-
|
28
|
-
# HTTP Basic for controller actions, using config_vars credentials.
|
29
|
-
def config_vars_auth(*args)
|
30
|
-
include AuthInstanceMethods
|
31
|
-
before_filter :config_vars_http_basic_check, *args
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# Included in controllers that call config_vars_controller.
|
36
|
-
module ControllerInstanceMethods
|
37
|
-
# GET /config_vars
|
38
|
-
def index
|
39
|
-
@config_vars = ConfigVar.order(:name).all
|
40
|
-
|
41
|
-
defined_names = ConfigvarsRails.variable_names
|
42
|
-
default_names = defined_names - @config_vars.map { |var| var.name.to_sym }
|
43
|
-
@default_vars = default_names.map { |name|
|
44
|
-
[name.to_s, ConfigvarsRails.variable_descriptor(name)]
|
45
|
-
}.sort
|
46
16
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
unless @config_var
|
62
|
-
@config_var = ConfigVar.new :name => params[:name]
|
63
|
-
if descriptor = ConfigvarsRails.variable_descriptor(params[:name])
|
64
|
-
@config_var.value = descriptor.default_value
|
17
|
+
# Included in controllers that include ConfivarsRails::Controller.
|
18
|
+
module InstanceMethods
|
19
|
+
# GET /config_vars
|
20
|
+
def index
|
21
|
+
@config_vars = ConfigVar.order(:name).all
|
22
|
+
|
23
|
+
defined_names = ConfigvarsRails.variable_names
|
24
|
+
default_names = defined_names - @config_vars.map { |var| var.name.to_sym }
|
25
|
+
@default_vars = default_names.map { |name|
|
26
|
+
[name.to_s, ConfigvarsRails.variable_descriptor(name)]
|
27
|
+
}.sort
|
28
|
+
|
29
|
+
respond_to do |format|
|
30
|
+
format.html # index.html.erb
|
65
31
|
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# PUT /config_vars/http_user
|
70
|
-
def update
|
71
|
-
@config_var = ConfigVar.where(:name => params[:name]).first
|
72
|
-
unless @config_var
|
73
|
-
@config_var = ConfigVar.new params[:config_var]
|
74
|
-
@config_var.name = params[:name]
|
75
32
|
end
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
33
|
+
|
34
|
+
# GET /config_vars/http_user
|
35
|
+
def show
|
36
|
+
edit
|
37
|
+
render :text => @config_var.value
|
38
|
+
end
|
39
|
+
|
40
|
+
# GET /config_vars/http_user/edit
|
41
|
+
def edit
|
42
|
+
@config_var = ConfigVar.where(:name => params[:name]).first
|
43
|
+
unless @config_var
|
44
|
+
@config_var = ConfigVar.new :name => params[:name]
|
45
|
+
if descriptor = ConfigvarsRails.variable_descriptor(params[:name])
|
46
|
+
@config_var.value = descriptor.default_value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# PUT /config_vars/http_user
|
52
|
+
def update
|
53
|
+
@config_var = ConfigVar.where(:name => params[:name]).first
|
54
|
+
unless @config_var
|
55
|
+
@config_var = ConfigVar.new params[:config_var]
|
56
|
+
@config_var.name = params[:name]
|
82
57
|
end
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
58
|
+
|
59
|
+
respond_to do |format|
|
60
|
+
success = if @config_var.new_record?
|
61
|
+
@config_var.save
|
62
|
+
else
|
63
|
+
@config_var.update_attributes(params[:config_var])
|
64
|
+
end
|
65
|
+
if success
|
66
|
+
format.html do
|
67
|
+
redirect_to config_vars_url,
|
68
|
+
:notice => 'Configuration variable was successfully updated.'
|
69
|
+
end
|
70
|
+
else
|
71
|
+
format.html { render :action => :edit }
|
87
72
|
end
|
88
|
-
else
|
89
|
-
format.html { render :action => :edit }
|
90
73
|
end
|
91
74
|
end
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end # module ConfigvarsRails::Session::ControllerInstanceMethods
|
104
|
-
|
105
|
-
# Included in controllers that call config_vars_controller.
|
106
|
-
module AuthInstanceMethods
|
107
|
-
def config_vars_http_basic_check
|
108
|
-
authenticate_or_request_with_http_basic(
|
109
|
-
ConfigVar['config_vars.http_realm']) do |user, password|
|
110
|
-
user == ConfigVar['config_vars.http_user'] &&
|
111
|
-
password == ConfigVar['config_vars.http_password']
|
75
|
+
|
76
|
+
# DELETE /config_vars/http_user
|
77
|
+
def destroy
|
78
|
+
@config_var = ConfigVar.where(:name => params[:name]).first
|
79
|
+
@config_var.destroy
|
80
|
+
|
81
|
+
respond_to do |format|
|
82
|
+
format.html { redirect_to(config_vars_url) }
|
83
|
+
end
|
112
84
|
end
|
113
|
-
end
|
114
|
-
private :config_vars_http_basic_check
|
115
|
-
end # module ConfigvarsRails::Session::AclInstanceMethods
|
116
|
-
|
117
|
-
ActionController::Base.send :include, ControllerMixin
|
85
|
+
end # module ConfigvarsRails::Controller::InstanceMethods
|
118
86
|
|
119
|
-
end #
|
87
|
+
end # module ConfigvarsRails::Controller
|
120
88
|
|
121
89
|
end # namespace ConfigvarsRails
|
@@ -1,74 +1,57 @@
|
|
1
|
-
require '
|
1
|
+
require 'active_support'
|
2
2
|
|
3
3
|
# :nodoc: namespace
|
4
4
|
module ConfigvarsRails
|
5
5
|
|
6
6
|
# :nodoc: namespace
|
7
7
|
module Model
|
8
|
+
extend ActiveSupport::Concern
|
8
9
|
|
9
|
-
|
10
|
-
# Mixed into ActiveRecord::Base
|
11
|
-
module ModelMixin
|
12
|
-
def self.included(base)
|
13
|
-
base.send :extend, ModelClassMethods
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
# Methods here become ActiveRecord::Base class methods.
|
19
|
-
module ModelClassMethods
|
20
|
-
# Extends the model to make it hold configuration variables.
|
21
|
-
def config_vars_model
|
10
|
+
included do
|
22
11
|
# The name of the configuration variable.
|
23
12
|
validates :name, :uniqueness => true, :length => 1..64, :presence => true
|
24
13
|
|
25
14
|
# The value of the configuration variable.
|
26
15
|
validates :value, :length => 0..1024, :exclusion => { :in => [nil] }
|
27
|
-
|
28
|
-
extend ModelMetaclassMethods
|
29
|
-
include ModelInstanceMethods
|
30
16
|
end
|
31
|
-
end # module ConfigvarsRails::Model::ModelClassMethods
|
32
17
|
|
33
18
|
|
34
|
-
#
|
35
|
-
module
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
19
|
+
# Class methods for models that include ConfigVarsRails::Model.
|
20
|
+
module ClassMethods
|
21
|
+
# Access configuration flags by ConfigVar['flag_name'].
|
22
|
+
def [](name)
|
23
|
+
var = where(:name => name).first
|
24
|
+
return var.value if var
|
25
|
+
|
26
|
+
descriptor = ConfigvarsRails.variable_descriptor name
|
27
|
+
return descriptor.default_value if descriptor
|
28
|
+
|
29
|
+
raise IndexError, "Configuration variable #{name} not found"
|
30
|
+
end
|
40
31
|
|
41
|
-
|
42
|
-
|
32
|
+
# Set configuration flags by ConfigVar['flag_name'] = 'flag_value'.
|
33
|
+
def []=(name, value)
|
34
|
+
flag = where(:name => name).first
|
35
|
+
flag ||= new :name => name
|
36
|
+
flag.value = value
|
37
|
+
flag.save!
|
38
|
+
value
|
39
|
+
end
|
40
|
+
end # module ConfigvarsRails::Model::ClassMethods
|
41
|
+
|
42
|
+
|
43
|
+
# Included in models that include ConfigVarsRails::Model.
|
44
|
+
module InstanceMethods
|
45
|
+
# The descriptor for this variable, or nil if no descriptor was defined.
|
46
|
+
def descriptor
|
47
|
+
ConfigvarsRails.variable_descriptor name
|
48
|
+
end
|
43
49
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
flag = where(:name => name).first
|
50
|
-
flag ||= new :name => name
|
51
|
-
flag.value = value
|
52
|
-
flag.save!
|
53
|
-
value
|
54
|
-
end
|
55
|
-
end # module ConfigvarsRails::Model::ModelMetaclassMethods
|
56
|
-
|
57
|
-
|
58
|
-
# Included in models that call config_vars_model.
|
59
|
-
module ModelInstanceMethods
|
60
|
-
# The descriptor for this variable, or nil if no descriptor was defined.
|
61
|
-
def descriptor
|
62
|
-
ConfigvarsRails.variable_descriptor name
|
63
|
-
end
|
64
|
-
|
65
|
-
# Use name instead of ID on all URLs.
|
66
|
-
def to_param
|
67
|
-
name
|
68
|
-
end
|
69
|
-
end # module ConfigvarsRails::Model::ModelInstanceMethods
|
70
|
-
|
71
|
-
ActiveRecord::Base.send :include, ModelMixin
|
50
|
+
# Use name instead of ID on all URLs.
|
51
|
+
def to_param
|
52
|
+
name
|
53
|
+
end
|
54
|
+
end # module ConfigvarsRails::Model::InstanceMethods
|
72
55
|
|
73
56
|
end # namespace ConfigvarsRails::Model
|
74
57
|
|
data/lib/configvars_rails.rb
CHANGED
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: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 4
|
9
8
|
- 5
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
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: 2011-06
|
18
|
+
date: 2011-07-06 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
type: :runtime
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- app/helpers/config_vars_helper.rb
|
121
121
|
- configvars_rails.gemspec
|
122
122
|
- lib/configvars_rails.rb
|
123
|
+
- lib/configvars_rails/auth.rb
|
123
124
|
- lib/configvars_rails/controller.rb
|
124
125
|
- lib/configvars_rails/descriptor.rb
|
125
126
|
- lib/configvars_rails/engine.rb
|