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 CHANGED
@@ -1 +1 @@
1
- 0.4.5
1
+ 0.5.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{configvars_rails}
8
- s.version = "0.4.5"
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-30}
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 'action_controller'
1
+ require 'active_support'
2
2
 
3
3
  # :nodoc: namespace
4
4
  module ConfigvarsRails
5
5
 
6
- # :nodoc: namespace
7
- module Session
8
-
9
- # Mixed into ActiveController::Base
10
- module ControllerMixin
11
- def self.included(base)
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
- # Turns the current controller into the config vars management controller.
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
- respond_to do |format|
48
- format.html # index.html.erb
49
- end
50
- end
51
-
52
- # GET /config_vars/http_user
53
- def show
54
- edit
55
- render :text => @config_var.value
56
- end
57
-
58
- # GET /config_vars/http_user/edit
59
- def edit
60
- @config_var = ConfigVar.where(:name => params[:name]).first
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
- respond_to do |format|
78
- success = if @config_var.new_record?
79
- @config_var.save
80
- else
81
- @config_var.update_attributes(params[:config_var])
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
- if success
84
- format.html do
85
- redirect_to config_vars_url,
86
- :notice => 'Configuration variable was successfully updated.'
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
- end
93
-
94
- # DELETE /config_vars/http_user
95
- def destroy
96
- @config_var = ConfigVar.where(:name => params[:name]).first
97
- @config_var.destroy
98
-
99
- respond_to do |format|
100
- format.html { redirect_to(config_vars_url) }
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 # namespace ConfigvarsRails::Session
87
+ end # module ConfigvarsRails::Controller
120
88
 
121
89
  end # namespace ConfigvarsRails
@@ -1,6 +1,6 @@
1
1
  # Configuration flags that are global to the installation.
2
2
  class ConfigVar < ActiveRecord::Base
3
- config_vars_model
3
+ include ConfigvarsRails::Model
4
4
 
5
5
  # Add your extensions to the ConfigVar class here.
6
6
  end
@@ -1,6 +1,6 @@
1
1
  # Viewing and changing configuration variables.
2
2
  class ConfigVarsController < ApplicationController
3
- config_vars_controller
3
+ include ConfigvarsRails::Controller
4
4
 
5
5
  config_vars_auth
6
6
  end
@@ -1,74 +1,57 @@
1
- require 'active_record'
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
- # Included in the metaclass of models that call config_vars_model.
35
- module ModelMetaclassMethods
36
- # Access configuration flags by ConfigVar['flag_name'].
37
- def [](name)
38
- var = where(:name => name).first
39
- return var.value if var
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
- descriptor = ConfigvarsRails.variable_descriptor name
42
- return descriptor.default_value if descriptor
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
- raise IndexError, "Configuration variable #{name} not found"
45
- end
46
-
47
- # Set configuration flags by ConfigVar['flag_name'] = 'flag_value'.
48
- def []=(name, value)
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
 
@@ -2,6 +2,7 @@
2
2
  module ConfigvarsRails
3
3
  end
4
4
 
5
+ require 'configvars_rails/auth.rb'
5
6
  require 'configvars_rails/controller.rb'
6
7
  require 'configvars_rails/descriptor.rb'
7
8
  require 'configvars_rails/model.rb'
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: 5
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
8
  - 5
10
- version: 0.4.5
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-30 00:00:00 Z
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