parlement 0.10 → 0.11
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/CHANGES +11 -0
- data/MEMORY +9 -1
- data/README +5 -4
- data/app/controllers/account_controller.rb +10 -13
- data/app/controllers/application.rb +4 -5
- data/app/controllers/elt_controller.rb +9 -7
- data/app/controllers/person_controller.rb +1 -3
- data/app/controllers/subscriber_controller.rb +10 -10
- data/app/helpers/elt_helper.rb +2 -0
- data/app/models/elt.rb +28 -19
- data/app/models/mail.rb +26 -14
- data/app/models/mail_notify.rb +5 -4
- data/app/models/person.rb +11 -2
- data/app/views/account/_login.rhtml +3 -3
- data/app/views/account/_show.rhtml +12 -14
- data/app/views/elt/_choice.rhtml +3 -3
- data/app/views/elt/_elt.rhtml +4 -4
- data/app/views/elt/_list.rhtml +2 -2
- data/app/views/elt/_listByDate.rhtml +1 -1
- data/app/views/elt/_listByVote.rhtml +1 -1
- data/app/views/elt/new.rhtml +3 -3
- data/app/views/elt/show.rhtml +2 -2
- data/app/views/layouts/top.rhtml +6 -0
- data/app/views/mail_notify/publish.text.html.rhtml +1 -1
- data/app/views/person/_listElts.rhtml +5 -3
- data/app/views/person/show.rhtml +1 -2
- data/config/boot.rb +5 -4
- data/config/environment.rb +6 -4
- data/config/routes.rb +3 -2
- data/db/development_structure.sql +15 -4
- data/db/migrate/006_last_activity.rb +10 -0
- data/db/schema.rb +67 -49
- data/public/dispatch.fcgi +1 -0
- data/public/javascripts/controls.js +41 -23
- data/public/javascripts/dragdrop.js +317 -99
- data/public/javascripts/effects.js +301 -166
- data/public/javascripts/prototype.js +932 -402
- data/public/stylesheets/default.css +3 -2
- data/test/unit/elt_test.rb +13 -0
- data/test/unit/mail_test.rb +3 -1
- data/vendor/plugins/engines/CHANGELOG +203 -99
- data/vendor/plugins/engines/MIT-LICENSE +1 -1
- data/vendor/plugins/engines/README +32 -384
- data/vendor/plugins/engines/Rakefile +14 -0
- data/vendor/plugins/engines/UPGRADING +93 -0
- data/vendor/plugins/engines/about.yml +7 -0
- data/vendor/plugins/engines/generators/plugin_migration/USAGE +45 -0
- data/vendor/plugins/engines/generators/plugin_migration/plugin_migration_generator.rb +79 -0
- data/vendor/plugins/engines/generators/plugin_migration/templates/plugin_migration.erb +13 -0
- data/vendor/plugins/engines/init.rb +34 -47
- data/vendor/plugins/engines/install.rb +32 -0
- data/vendor/plugins/engines/lib/engines/{ruby_extensions.rb → deprecated_config_support.rb} +135 -113
- data/vendor/plugins/engines/lib/engines/plugin.rb +214 -0
- data/vendor/plugins/engines/lib/engines/plugin_list.rb +31 -0
- data/vendor/plugins/engines/lib/engines/plugin_migrator.rb +60 -0
- data/vendor/plugins/engines/lib/engines/rails_extensions/active_record.rb +19 -0
- data/vendor/plugins/engines/lib/engines/rails_extensions/dependencies.rb +143 -0
- data/vendor/plugins/engines/lib/engines/rails_extensions/migrations.rb +155 -0
- data/vendor/plugins/engines/lib/engines/rails_extensions/public_asset_helpers.rb +116 -0
- data/vendor/plugins/engines/lib/engines/rails_extensions/rails.rb +20 -0
- data/vendor/plugins/engines/lib/engines/rails_extensions/rails_initializer.rb +86 -0
- data/vendor/plugins/engines/lib/engines/rails_extensions/routing.rb +77 -0
- data/vendor/plugins/engines/lib/engines/rails_extensions/templates.rb +140 -0
- data/vendor/plugins/engines/lib/engines/rails_extensions.rb +6 -0
- data/vendor/plugins/engines/lib/engines/testing.rb +88 -0
- data/vendor/plugins/engines/lib/engines.rb +281 -425
- data/vendor/plugins/engines/tasks/engines.rake +108 -137
- metadata +218 -250
- data/db/ROOT/perso.txt +0 -214
- data/public/images/indicator.gif +0 -0
- data/public/images/orange_by_darren_Hester_350o.jpg +0 -0
- data/public/images/smile.png +0 -0
- data/vendor/plugins/engines/generators/engine/USAGE +0 -26
- data/vendor/plugins/engines/generators/engine/engine_generator.rb +0 -199
- data/vendor/plugins/engines/generators/engine/templates/README +0 -85
- data/vendor/plugins/engines/generators/engine/templates/init_engine.erb +0 -15
- data/vendor/plugins/engines/generators/engine/templates/install.erb +0 -4
- data/vendor/plugins/engines/generators/engine/templates/lib/engine.erb +0 -6
- data/vendor/plugins/engines/generators/engine/templates/licenses/GPL +0 -18
- data/vendor/plugins/engines/generators/engine/templates/licenses/LGPL +0 -19
- data/vendor/plugins/engines/generators/engine/templates/licenses/MIT +0 -22
- data/vendor/plugins/engines/generators/engine/templates/licenses/None +0 -1
- data/vendor/plugins/engines/generators/engine/templates/public/javascripts/engine.js +0 -0
- data/vendor/plugins/engines/generators/engine/templates/public/stylesheets/engine.css +0 -0
- data/vendor/plugins/engines/generators/engine/templates/tasks/engine.rake +0 -0
- data/vendor/plugins/engines/generators/engine/templates/test/test_helper.erb +0 -17
- data/vendor/plugins/engines/lib/bundles/require_resource.rb +0 -124
- data/vendor/plugins/engines/lib/bundles.rb +0 -77
- data/vendor/plugins/engines/lib/engines/action_mailer_extensions.rb +0 -140
- data/vendor/plugins/engines/lib/engines/action_view_extensions.rb +0 -141
- data/vendor/plugins/engines/lib/engines/active_record_extensions.rb +0 -21
- data/vendor/plugins/engines/lib/engines/dependencies_extensions.rb +0 -129
- data/vendor/plugins/engines/lib/engines/migration_extensions.rb +0 -53
- data/vendor/plugins/engines/lib/engines/routing_extensions.rb +0 -28
- data/vendor/plugins/engines/lib/engines/testing_extensions.rb +0 -327
- data/vendor/plugins/engines/tasks/deprecated_engines.rake +0 -7
- data/vendor/plugins/engines/test/action_view_extensions_test.rb +0 -9
- data/vendor/plugins/engines/test/ruby_extensions_test.rb +0 -115
- data/vendor/plugins/guid/README.TXT +0 -29
- data/vendor/plugins/guid/init.rb +0 -30
- data/vendor/plugins/guid/lib/usesguid.rb +0 -37
- data/vendor/plugins/guid/lib/uuid22.rb +0 -43
- data/vendor/plugins/guid/lib/uuidtools.rb +0 -572
- data/vendor/plugins/responds_to_parent/MIT-LICENSE +0 -20
- data/vendor/plugins/responds_to_parent/README +0 -42
- data/vendor/plugins/responds_to_parent/Rakefile +0 -22
- data/vendor/plugins/responds_to_parent/init.rb +0 -1
- data/vendor/plugins/responds_to_parent/lib/responds_to_parent.rb +0 -46
- data/vendor/plugins/responds_to_parent/test/responds_to_parent_test.rb +0 -115
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Generates a migration which migrates all plugins to their latest versions
|
|
2
|
+
# within the database.
|
|
3
|
+
class PluginMigrationGenerator < Rails::Generator::Base
|
|
4
|
+
|
|
5
|
+
def initialize(runtime_args, runtime_options={})
|
|
6
|
+
super
|
|
7
|
+
@options = {:assigns => {}}
|
|
8
|
+
|
|
9
|
+
ensure_plugin_schema_table_exists
|
|
10
|
+
get_plugins_to_migrate(runtime_args)
|
|
11
|
+
|
|
12
|
+
if @plugins_to_migrate.empty?
|
|
13
|
+
puts "All plugins are migrated to their latest versions"
|
|
14
|
+
exit(0)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
@options[:migration_file_name] = build_migration_name
|
|
18
|
+
@options[:assigns][:class_name] = build_migration_name.classify
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def manifest
|
|
22
|
+
record do |m|
|
|
23
|
+
m.migration_template 'plugin_migration.erb', 'db/migrate', @options
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
protected
|
|
28
|
+
|
|
29
|
+
# Create the plugin schema table if it doesn't already exist. See
|
|
30
|
+
# Engines::RailsExtensions::Migrations#initialize_schema_information_with_engine_additions
|
|
31
|
+
def ensure_plugin_schema_table_exists
|
|
32
|
+
ActiveRecord::Base.connection.initialize_schema_information
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Determine all the plugins which have migrations that aren't present
|
|
36
|
+
# according to the plugin schema information from the database.
|
|
37
|
+
def get_plugins_to_migrate(plugin_names)
|
|
38
|
+
|
|
39
|
+
# First, grab all the plugins which exist and have migrations
|
|
40
|
+
@plugins_to_migrate = if plugin_names.empty?
|
|
41
|
+
Rails.plugins
|
|
42
|
+
else
|
|
43
|
+
plugin_names.map do |name|
|
|
44
|
+
Rails.plugins[name] ? Rails.plugins[name] : raise("Cannot find the plugin '#{name}'")
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
@plugins_to_migrate.reject! { |p| p.latest_migration.nil? }
|
|
49
|
+
|
|
50
|
+
# Then find the current versions from the database
|
|
51
|
+
@current_versions = {}
|
|
52
|
+
@plugins_to_migrate.each do |plugin|
|
|
53
|
+
@current_versions[plugin.name] = Engines::PluginMigrator.current_version(plugin)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Then find the latest versions from their migration directories
|
|
57
|
+
@new_versions = {}
|
|
58
|
+
@plugins_to_migrate.each do |plugin|
|
|
59
|
+
@new_versions[plugin.name] = plugin.latest_migration
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Remove any plugins that don't need migration
|
|
63
|
+
@plugins_to_migrate.map { |p| p.name }.each do |name|
|
|
64
|
+
@plugins_to_migrate.delete(Rails.plugins[name]) if @current_versions[name] == @new_versions[name]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
@options[:assigns][:plugins] = @plugins_to_migrate
|
|
68
|
+
@options[:assigns][:new_versions] = @new_versions
|
|
69
|
+
@options[:assigns][:current_versions] = @current_versions
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Construct a unique migration name based on the plugins involved and the
|
|
73
|
+
# versions they should reach after this migration is run.
|
|
74
|
+
def build_migration_name
|
|
75
|
+
@plugins_to_migrate.map do |plugin|
|
|
76
|
+
"#{plugin.name}_to_version_#{@new_versions[plugin.name]}"
|
|
77
|
+
end.join("_and_")
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class <%= class_name %> < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
<%- plugins.each do |plugin| -%>
|
|
4
|
+
Rails.plugins["<%= plugin.name %>"].migrate(<%= new_versions[plugin.name] %>)
|
|
5
|
+
<%- end -%>
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def self.down
|
|
9
|
+
<%- plugins.each do |plugin| -%>
|
|
10
|
+
Rails.plugins["<%= plugin.name %>"].migrate(<%= current_versions[plugin.name] %>)
|
|
11
|
+
<%- end -%>
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -1,53 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
#
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
|
8
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
9
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
|
10
|
-
# the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be
|
|
13
|
-
# included in all copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
19
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
20
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
# = IN OTHER WORDS:
|
|
26
|
-
#
|
|
27
|
-
# You are free to use this software as you please, but if it breaks you'd
|
|
28
|
-
# best not come a'cryin...
|
|
29
|
-
#++
|
|
1
|
+
begin
|
|
2
|
+
silence_warnings { require 'rails/version' } # it may already be loaded
|
|
3
|
+
unless Rails::VERSION::MAJOR >= 1 && Rails::VERSION::MINOR >= 2
|
|
4
|
+
raise "This version of the engines plugin requires Rails 1.2 or later!"
|
|
5
|
+
end
|
|
6
|
+
end
|
|
30
7
|
|
|
31
|
-
#
|
|
32
|
-
require
|
|
33
|
-
require 'bundles'
|
|
8
|
+
# First, require the engines module & core methods
|
|
9
|
+
require "engines"
|
|
34
10
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
11
|
+
# Load this before we get actually start engines
|
|
12
|
+
require "engines/rails_extensions/rails_initializer"
|
|
13
|
+
|
|
14
|
+
# Start the engines mechanism.
|
|
15
|
+
Engines.init(config, self)
|
|
40
16
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
17
|
+
# Now that we've defined the engines module, load up any extensions
|
|
18
|
+
[:rails,
|
|
19
|
+
:rails_initializer,
|
|
20
|
+
:dependencies,
|
|
21
|
+
:active_record,
|
|
22
|
+
:migrations,
|
|
23
|
+
:templates,
|
|
24
|
+
:public_asset_helpers,
|
|
25
|
+
:routing
|
|
26
|
+
].each do |f|
|
|
27
|
+
require "engines/rails_extensions/#{f}"
|
|
47
28
|
end
|
|
48
29
|
|
|
49
|
-
#
|
|
50
|
-
|
|
30
|
+
# Load the testing extensions, if we are in the test environment.
|
|
31
|
+
require "engines/testing" if RAILS_ENV == "test"
|
|
51
32
|
|
|
52
|
-
#
|
|
53
|
-
|
|
33
|
+
# Load the Rails::Info module so that plugins can insert information into it.
|
|
34
|
+
begin
|
|
35
|
+
require 'rails/info'
|
|
36
|
+
rescue Exception
|
|
37
|
+
# If this file can't be loaded, it's probably because we're running in an
|
|
38
|
+
# environment where Rails' builtins aren't yet in the load path.
|
|
39
|
+
# For the moment, just ignore this. See Ticket #261
|
|
40
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "..", "rails", "railties", "lib")
|
|
2
|
+
silence_warnings { require 'rails/version' } # it may already be loaded.
|
|
3
|
+
|
|
4
|
+
unless Rails::VERSION::MAJOR >= 1 && Rails::VERSION::MINOR >= 2
|
|
5
|
+
puts <<-end_of_warning
|
|
6
|
+
|
|
7
|
+
!!!=== IMPORTANT NOTE ===!!!
|
|
8
|
+
|
|
9
|
+
Support for Rails < 1.2 has been dropped; if you are using
|
|
10
|
+
Rails =< 1.1.6, please use Engines 1.1.6, available from:
|
|
11
|
+
|
|
12
|
+
>> http://svn.rails-engines.org/engines/tags/rel_1.1.6
|
|
13
|
+
|
|
14
|
+
For more details about changes in Engines 1.2, please see
|
|
15
|
+
the changelog or the website:
|
|
16
|
+
|
|
17
|
+
>> http://www.rails-engines.org
|
|
18
|
+
|
|
19
|
+
end_of_warning
|
|
20
|
+
else
|
|
21
|
+
puts <<-end_of_message
|
|
22
|
+
|
|
23
|
+
The engines plugin is now installed. Feels good, right? Yeah.
|
|
24
|
+
You knew it would.
|
|
25
|
+
|
|
26
|
+
Once the warm, fuzzy glow has subsided, be sure to read the contents
|
|
27
|
+
of the README and UPGRADING files if you're migrating this application
|
|
28
|
+
from Rails 1.1.x to 1.2.x.
|
|
29
|
+
|
|
30
|
+
Have a great day!
|
|
31
|
+
end_of_message
|
|
32
|
+
end
|
|
@@ -1,113 +1,135 @@
|
|
|
1
|
-
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
#
|
|
49
|
-
#
|
|
50
|
-
#
|
|
51
|
-
#
|
|
52
|
-
#
|
|
53
|
-
#
|
|
54
|
-
#
|
|
55
|
-
#
|
|
56
|
-
#
|
|
57
|
-
#
|
|
58
|
-
#
|
|
59
|
-
#
|
|
60
|
-
#
|
|
61
|
-
#
|
|
62
|
-
#
|
|
63
|
-
#
|
|
64
|
-
#
|
|
65
|
-
#
|
|
66
|
-
#
|
|
67
|
-
#
|
|
68
|
-
#
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
#
|
|
72
|
-
#
|
|
73
|
-
#
|
|
74
|
-
#
|
|
75
|
-
#
|
|
76
|
-
#
|
|
77
|
-
#
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
1
|
+
# This file contains support for the now-deprecated +config+ method that the engines
|
|
2
|
+
# plugin provided before version 1.2. Instead of using this, plugin authors are
|
|
3
|
+
# now encouraged to create their own Module configuration mechanisms; the
|
|
4
|
+
# +mattr_accessor+ mechanism provided by ActiveSupport is ideal for this:
|
|
5
|
+
#
|
|
6
|
+
# module MyPlugin
|
|
7
|
+
# mattr_accessor :config_value
|
|
8
|
+
# self.config_value = "default"
|
|
9
|
+
# end
|
|
10
|
+
#
|
|
11
|
+
# == Using the deprecated config method
|
|
12
|
+
#
|
|
13
|
+
# If you require the config method to be present, change your <tt>environment.rb</tt>
|
|
14
|
+
# file such that the very top of the file looks like this:
|
|
15
|
+
#
|
|
16
|
+
# require File.join(File.dirname(__FILE__), 'boot')
|
|
17
|
+
# require File.join(RAILS_ROOT, "vendor", "plugins", "engines",
|
|
18
|
+
# "lib", "engines", "deprecated_config_support")
|
|
19
|
+
#
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# Adds the +config+ and +default_constant+ methods to Module.
|
|
23
|
+
#
|
|
24
|
+
# *IMPORTANT NOTE* - these methods are deprecated. Only use them when you have no
|
|
25
|
+
# other choice. See link:files/lib/engines/deprecated_config_support_rb.html for more
|
|
26
|
+
# information.
|
|
27
|
+
class Module
|
|
28
|
+
# Defines a constant within a module/class ONLY if that constant does
|
|
29
|
+
# not already exist.
|
|
30
|
+
#
|
|
31
|
+
# This can be used to implement defaults in plugins/engines/libraries, e.g.
|
|
32
|
+
# if a plugin module exists:
|
|
33
|
+
# module MyPlugin
|
|
34
|
+
# default_constant :MyDefault, "the_default_value"
|
|
35
|
+
# end
|
|
36
|
+
#
|
|
37
|
+
# then developers can override this default by defining that constant at
|
|
38
|
+
# some point *before* the module/plugin gets loaded (such as environment.rb)
|
|
39
|
+
def default_constant(name, value)
|
|
40
|
+
if !(name.is_a?(String) or name.is_a?(Symbol))
|
|
41
|
+
raise "Cannot use a #{name.class.name} ['#{name}'] object as a constant name"
|
|
42
|
+
end
|
|
43
|
+
if !self.const_defined?(name)
|
|
44
|
+
self.class_eval("#{name} = #{value.inspect}")
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# A mechanism for defining configuration of Modules. With this
|
|
49
|
+
# mechanism, default values for configuration can be provided within shareable
|
|
50
|
+
# code, and the end user can customise the configuration without having to
|
|
51
|
+
# provide all values.
|
|
52
|
+
#
|
|
53
|
+
# Example:
|
|
54
|
+
#
|
|
55
|
+
# module MyModule
|
|
56
|
+
# config :param_one, "some value"
|
|
57
|
+
# config :param_two, 12345
|
|
58
|
+
# end
|
|
59
|
+
#
|
|
60
|
+
# Those values can now be accessed by the following method
|
|
61
|
+
#
|
|
62
|
+
# MyModule.config :param_one
|
|
63
|
+
# => "some value"
|
|
64
|
+
# MyModule.config :param_two
|
|
65
|
+
# => 12345
|
|
66
|
+
#
|
|
67
|
+
# ... or, if you have overrriden the method 'config'
|
|
68
|
+
#
|
|
69
|
+
# MyModule::CONFIG[:param_one]
|
|
70
|
+
# => "some value"
|
|
71
|
+
# MyModule::CONFIG[:param_two]
|
|
72
|
+
# => 12345
|
|
73
|
+
#
|
|
74
|
+
# Once a value is stored in the configuration, it will not be altered
|
|
75
|
+
# by subsequent assignments, unless a special flag is given:
|
|
76
|
+
#
|
|
77
|
+
# (later on in your code, most likely in another file)
|
|
78
|
+
# module MyModule
|
|
79
|
+
# config :param_one, "another value"
|
|
80
|
+
# config :param_two, 98765, :force
|
|
81
|
+
# end
|
|
82
|
+
#
|
|
83
|
+
# The configuration is now:
|
|
84
|
+
#
|
|
85
|
+
# MyModule.config :param_one
|
|
86
|
+
# => "some value" # not changed
|
|
87
|
+
# MyModule.config :param_two
|
|
88
|
+
# => 98765
|
|
89
|
+
#
|
|
90
|
+
# Configuration values can also be given as a Hash:
|
|
91
|
+
#
|
|
92
|
+
# MyModule.config :param1 => 'value1', :param2 => 'value2'
|
|
93
|
+
#
|
|
94
|
+
# Setting of these values can also be forced:
|
|
95
|
+
#
|
|
96
|
+
# MyModule.config :param1 => 'value3', :param2 => 'value4', :force => true
|
|
97
|
+
#
|
|
98
|
+
# A value of anything other than false or nil given for the :force key will
|
|
99
|
+
# result in the new values *always* being set.
|
|
100
|
+
def config(*args)
|
|
101
|
+
|
|
102
|
+
raise "config expects at least one argument" if args.empty?
|
|
103
|
+
|
|
104
|
+
# extract the arguments
|
|
105
|
+
if args[0].is_a?(Hash)
|
|
106
|
+
override = args[0][:force]
|
|
107
|
+
args[0].delete(:force)
|
|
108
|
+
args[0].each { |key, value| _handle_config(key, value, override)}
|
|
109
|
+
else
|
|
110
|
+
_handle_config(*args)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
private
|
|
115
|
+
# Actually set the config values
|
|
116
|
+
def _handle_config(name, value=nil, override=false)
|
|
117
|
+
if !self.const_defined?("CONFIG")
|
|
118
|
+
self.class_eval("CONFIG = {}")
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
if value != nil
|
|
122
|
+
if override or self::CONFIG[name] == nil
|
|
123
|
+
self::CONFIG[name] = value
|
|
124
|
+
end
|
|
125
|
+
else
|
|
126
|
+
# if we pass an array of config keys to config(),
|
|
127
|
+
# get the array of values back
|
|
128
|
+
if name.is_a? Array
|
|
129
|
+
name.map { |c| self::CONFIG[c] }
|
|
130
|
+
else
|
|
131
|
+
self::CONFIG[name]
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|