summaryrefslogtreecommitdiff
path: root/app/models/gs_parameter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/gs_parameter.rb')
-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