summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-05 12:42:53 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-05 12:42:53 +0100
commit01f2ab4e3d5694de81f6ebb594e0e852616ebbd9 (patch)
tree48613822df4082b080e1ecb68a6c38c1fbdadbfb /app/models
parent380a4cdfe5cfa573fb916ca7c2145a6062ef8198 (diff)
Added GsParameter model as a replacement for gemeinschaft_parameters.rb
Diffstat (limited to 'app/models')
-rw-r--r--app/models/gs_parameter.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/models/gs_parameter.rb b/app/models/gs_parameter.rb
new file mode 100644
index 0000000..d0cc37a
--- /dev/null
+++ b/app/models/gs_parameter.rb
@@ -0,0 +1,28 @@
+class GsParameter < ActiveRecord::Base
+ validates :name,
+ :presence => true,
+ :uniqueness => true
+
+ validates :value,
+ :presence => true
+
+ validates :class_type,
+ :presence => true,
+ :inclusion => { :in => ['String', 'Integer', 'Boolean', 'YAML'] }
+
+ def generate_contant
+ 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'
+ end
+
+ Kernel.const_set(self.name, YAML.load(self.value)) if self.class_type == 'YAML'
+ end
+
+ def to_s
+ name
+ end
+end