To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / plugins / redmine_checkout / lib / checkout / setting_patch.rb @ 1318:9c2a5a4514a8
History | View | Annotate | Download (2.16 KB)
| 1 |
require_dependency 'setting'
|
|---|---|
| 2 |
|
| 3 |
module Checkout |
| 4 |
module SettingPatch |
| 5 |
def self.included(base) # :nodoc: |
| 6 |
base.extend(ClassMethods)
|
| 7 |
|
| 8 |
base.class_eval do
|
| 9 |
unloadable |
| 10 |
|
| 11 |
# Defines getter and setter for each setting
|
| 12 |
# Then setting values can be read using: Setting.some_setting_name
|
| 13 |
# or set using Setting.some_setting_name = "some value"
|
| 14 |
Redmine::Plugin.find(:redmine_checkout).settings[:default].keys.each do |name| |
| 15 |
if name.start_with?('protocols_') |
| 16 |
default = "[]"
|
| 17 |
else
|
| 18 |
default = <<-END_SRC |
| 19 |
begin
|
| 20 |
default = Setting.available_settings['plugin_redmine_checkout']['default']['#{name}']
|
| 21 |
# perform a deep copy of the default
|
| 22 |
Marshal::load(Marshal::dump(default))
|
| 23 |
end
|
| 24 |
END_SRC
|
| 25 |
end
|
| 26 |
|
| 27 |
src = <<-END_SRC |
| 28 |
def self.checkout_#{name}
|
| 29 |
self.plugin_redmine_checkout[:#{name}] || #{default}
|
| 30 |
end
|
| 31 |
|
| 32 |
def self.checkout_#{name}?
|
| 33 |
self.checkout_#{name}.to_i > 0
|
| 34 |
end
|
| 35 |
|
| 36 |
def self.checkout_#{name}=(value)
|
| 37 |
setting = Setting.plugin_redmine_checkout
|
| 38 |
setting[:#{name}] = value
|
| 39 |
Setting.plugin_redmine_checkout = setting
|
| 40 |
end
|
| 41 |
END_SRC
|
| 42 |
class_eval src, __FILE__, __LINE__ |
| 43 |
end
|
| 44 |
|
| 45 |
class <<self |
| 46 |
alias_method :store_without_checkout, :[]= |
| 47 |
alias_method :[]=, :store_with_checkout |
| 48 |
|
| 49 |
alias_method :retrieve_without_checkout, :[] |
| 50 |
alias_method :[], :retrieve_with_checkout |
| 51 |
end
|
| 52 |
end
|
| 53 |
end
|
| 54 |
|
| 55 |
module ClassMethods |
| 56 |
def store_with_checkout(name, value) |
| 57 |
if name.to_s.starts_with? "checkout_" |
| 58 |
self.send("#{name}=", value) |
| 59 |
else
|
| 60 |
store_without_checkout(name, value) |
| 61 |
end
|
| 62 |
end
|
| 63 |
|
| 64 |
def retrieve_with_checkout(name) |
| 65 |
if name.to_s.starts_with? "checkout_" |
| 66 |
self.send("#{name}") |
| 67 |
else
|
| 68 |
retrieve_without_checkout(name) |
| 69 |
end
|
| 70 |
end
|
| 71 |
end
|
| 72 |
end
|
| 73 |
end
|
| 74 |
|
| 75 |
Setting.send(:include, Checkout::SettingPatch) |