summaryrefslogtreecommitdiff
path: root/app/models/gs_parameter.rb
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-05 23:01:16 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-05 23:01:16 +0100
commitddb3dfa92ec0878240211cb2b7a8e125961b1360 (patch)
tree0111ac9f589d97503046d9a81cd3af841e17501d /app/models/gs_parameter.rb
parente76890d5f4634d47514a592d501d9792ae2ff7bb (diff)
Moved to GsParemeter.get and set defaults for a couple of validations.
Diffstat (limited to 'app/models/gs_parameter.rb')
-rw-r--r--app/models/gs_parameter.rb25
1 files changed, 16 insertions, 9 deletions
diff --git a/app/models/gs_parameter.rb b/app/models/gs_parameter.rb
index 8e30583..9d9e996 100644
--- a/app/models/gs_parameter.rb
+++ b/app/models/gs_parameter.rb
@@ -12,16 +12,23 @@ class GsParameter < ActiveRecord::Base
:presence => true,
:inclusion => { :in => ['String', 'Integer', 'Boolean', 'YAML'] }
- def generate_constant
- Kernel.const_set(self.name, self.value.to_i) if self.class_type == 'Integer'
- Kernel.const_set(self.name, self.value.to_s) if self.class_type == 'String'
-
- if self.class_type == 'Boolean'
- Kernel.const_set(self.name, true) if self.value == 'true'
- Kernel.const_set(self.name, false) if self.value == 'false'
+ def self.get(wanted_variable)
+ if GsParameter.table_exists?
+ item = GsParameter.where(:name => wanted_variable).first
+ if item.nil?
+ return nil
+ else
+ return item.value.to_i if item.class_type == 'Integer'
+ return item.value.to_s if item.class_type == 'String'
+ if item.class_type == 'Boolean'
+ return true if item.value == 'true'
+ return false if item.value == 'false'
+ end
+ return YAML.load(item.value) if item.class_type == 'YAML'
+ end
+ else
+ nil
end
-
- Kernel.const_set(self.name, YAML.load(self.value)) if self.class_type == 'YAML'
end
def to_s