@@ -7,34 +7,13 @@ class FieldConfig < ActiveRecord::Base
7
7
validates_presence_of :key , :field_id , :screen_id
8
8
validates_uniqueness_of :key , :scope => [ :screen_id , :field_id ]
9
9
10
- # Enable hash-like access to table for ease of use
11
- # Shortcut for self.get(key)
12
- def self . []( key )
13
- self . get ( key . to_s )
14
- end
15
-
16
- # Make setting values from Rails nice and easy
17
- def self . set ( key , value )
18
- #only set this if the config already exists
19
- setting = FieldConfig . where ( :key => key ) . first
20
- setting . update_column ( :value , value )
21
- end
22
-
23
- # Make getting values from Rails nice and easy
24
- # Returns false if key isn't found or the config is broken.
25
- def self . get ( key )
26
- setting = FieldConfig . where ( :key => key ) . first
27
- if setting . nil?
28
- raise "Field config key #{ key } not found!"
29
- end
30
- return setting . value
31
- end
32
-
33
- # Creates a Field Config entry by taking the key and value desired
34
- def self . make_field_config ( field_id , config_key , config_value )
35
- # first_or_create: check whether first returns nil or not; if it does return nil, create is called
36
- FieldConfig . where ( :key => config_key ) . first_or_create ( :field_id => field_id , :key => config_key , :value => config_value )
37
- end
38
-
10
+ def self . get ( screen , field , key )
11
+ field_config = FieldConfig . where ( :screen_id => screen . id , :field_id => field . id , :key => key ) . first
12
+ if !field_config . nil?
13
+ return field_config . value
14
+ else
15
+ return nil
16
+ end
17
+ end
39
18
end
40
19
0 commit comments